Skip to content

Commit

Permalink
[FIXED JENKINS-43396] Global NodePropertys should be in environment
Browse files Browse the repository at this point in the history
They currently show up once you enter a node block, but not for things
outside node blocks. This fixes that by adding them to
WorkflowRun.getEnvironment(listener).
  • Loading branch information
abayer committed Apr 6, 2017
1 parent a47154b commit 3fd2761
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Expand Up @@ -56,6 +56,7 @@
import hudson.scm.SCM;
import hudson.scm.SCMRevisionState;
import hudson.security.ACL;
import hudson.slaves.NodeProperty;
import hudson.util.DaemonThreadFactory;
import hudson.util.Iterators;
import hudson.util.NamingThreadFactory;
Expand Down Expand Up @@ -391,6 +392,11 @@ public void doKill() {

@Override public EnvVars getEnvironment(TaskListener listener) throws IOException, InterruptedException {
EnvVars env = super.getEnvironment(listener);

for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) {
nodeProperty.buildEnvVars(env,listener);
}

// TODO EnvironmentContributingAction does not support Job yet:
ParametersAction a = getAction(ParametersAction.class);
if (a != null) {
Expand Down
Expand Up @@ -43,6 +43,11 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import jenkins.model.CauseOfInterruption;
import jenkins.model.InterruptedBuildAction;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -326,4 +331,20 @@ public void parallelBranchLabels() throws Exception {
r.assertLogContains("[b] b-inside-2", b);
}

@Test
@Issue("JENKINS-43396")
public void globalNodePropertiesInEnv() throws Exception {
DescribableList<NodeProperty<?>, NodePropertyDescriptor> original = r.jenkins.getGlobalNodeProperties();
EnvironmentVariablesNodeProperty envProp = new EnvironmentVariablesNodeProperty(
new EnvironmentVariablesNodeProperty.Entry("KEY", "VALUE"));

original.add(envProp);

WorkflowJob j = r.jenkins.createProject(WorkflowJob.class, "envVars");
j.setDefinition(new CpsFlowDefinition("echo \"KEY is ${env.KEY}\"", true));

WorkflowRun b = r.assertBuildStatusSuccess(j.scheduleBuild2(0));
r.assertLogContains("KEY is " + envProp.getEnvVars().get("KEY"), b);
}

}

0 comments on commit 3fd2761

Please sign in to comment.