Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
JENKINS-43330
- Loading branch information
Showing
8 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/inneractive/jenkins/plugins/consul/operations/ConsulSetKV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.inneractive.jenkins.plugins.consul.operations; | ||
|
||
import com.ecwid.consul.v1.ConsulClient; | ||
import com.ecwid.consul.v1.Response; | ||
import com.inneractive.jenkins.plugins.consul.ConsulOperation; | ||
import com.inneractive.jenkins.plugins.consul.ConsulOperationDescriptor; | ||
import hudson.Extension; | ||
import hudson.Launcher; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.util.FormValidation; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.QueryParameter; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Created by lioz on 7/26/17. | ||
*/ | ||
public class ConsulSetKV extends ConsulOperation { | ||
|
||
private final String valuePath; | ||
private final String value; | ||
|
||
@DataBoundConstructor | ||
public ConsulSetKV(String valuePath, String value) { | ||
this.valuePath = valuePath; | ||
this.value = value; | ||
} | ||
|
||
public String getValuePath() { | ||
return valuePath; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean perform(Run build, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { | ||
String finalValue = build.getEnvironment(listener).get(this.value); | ||
if (finalValue == null || finalValue.isEmpty()){ | ||
finalValue = value; | ||
} | ||
Response<Boolean> kvResponse = new ConsulClient("localhost").setKVValue(valuePath, value); | ||
return kvResponse.getValue(); | ||
} | ||
|
||
@Override | ||
public String getOperationName() { | ||
return "SetKeyValueStore"; | ||
} | ||
|
||
@Override | ||
public String getVariableName() { | ||
return value; | ||
} | ||
|
||
@Extension(optional = true) | ||
public static class DescriptorImpl extends ConsulOperationDescriptor { | ||
@Override | ||
public String getDisplayName() { | ||
return "Set a value in K/V store"; | ||
} | ||
|
||
public FormValidation doCheckValuePath(@QueryParameter String value) { | ||
if (value.isEmpty()) | ||
return FormValidation.error("Path is a mandatory field"); | ||
return FormValidation.ok(); | ||
} | ||
|
||
public FormValidation doCheckValue(@QueryParameter String value) { | ||
if (value.isEmpty()) | ||
return FormValidation.error("Environment variable name is a mandatory field"); | ||
return FormValidation.ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...main/resources/com/inneractive/jenkins/plugins/consul/operations/ConsulSetKV/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> | ||
<f:entry title="K/V path" field="valuePath"> | ||
<f:textbox /> | ||
</f:entry> | ||
<f:entry title="value" field="value"> | ||
<f:textbox /> | ||
</f:entry> | ||
</j:jelly> | ||
|
||
|
||
|
3 changes: 3 additions & 0 deletions
3
...n/resources/com/inneractive/jenkins/plugins/consul/operations/ConsulSetKV/help-value.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
Value or ENV var name to use. | ||
</div> |
4 changes: 4 additions & 0 deletions
4
...sources/com/inneractive/jenkins/plugins/consul/operations/ConsulSetKV/help-valuePath.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
Consul path to set with your value.<BR/> | ||
e.g. mysql/config/users/admin | ||
</div> |