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

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/643c8be5-6315-4684-9433-c2e3e90faa67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to