So, I am re-writing the Consul-KV-Builder Plugin (
https://wiki.jenkins-ci.org/display/JENKINS/Consul-KV-Builder+Plugin) to work with Jenkins pipeline. I have it working fine, except for writing ENV variables that can written and read when pipeline calls the build step.
Here is my step call:
... step([$class: 'ConsulKVBuilder', debugMode: 'ENABLED', envVarKey: 'test_key', hostUrl: '<HOST_URL_GOES_HERE>', key: 'test/test-key', keyValue: '', requestMode: 'READ', token: '', urlOverride: '']) ...
Here are the ways I am trying to set/get the ENV variable:
... String storageKey = this.envVarKey.replace('.', '_').replace('/', '_'); ...
... VariableInjectionAction action = new VariableInjectionAction(storageKey, value);
build.addAction(action);...
... static final class VariableInjectionAction implements Action, EnvironmentContributingAction {
private String key;
private String value;
public VariableInjectionAction(String key, String value) {
this.key = key;
this.value = value;
}
@Override
public void buildEnvVars(AbstractBuild build, EnvVars envVars) {
if (envVars != null && key != null && value != null) {
envVars.put(key, value);
}
}
@Override
public String getDisplayName() {
return "VariableInjectionAction";
}
@Override
public String getIconFileName() {
return null;
}
@Override
public String getUrlName() {
return null;
}
} ...
I have also tried:
... build.getEnvironment(listener).put(storageKey, value); ...
These work when I use the Consul KV Builder as a freestyle job step. When I call it from a pipeline script, the step executes with no errors, but the ENV variable value is null, both in the pipeline script and in the plugin log itself.
... logger.println(String.format("Stored ENV variable (k,v): %s=%s", storageKey, build.getEnvironment
(listener).get(storageKey, null))); ...
Am I running in a Jenkins Pipeline Plugin environment scoping issue?
-Jimmy