Skip to content
Permalink
Browse files
[JENKINS-28131] Improving the test and adding some inline comments
  • Loading branch information
recena committed Jun 29, 2015
1 parent 6a64190 commit a7abe6c0efab953cb8782eaef72d0cc54ec712d1
@@ -4,6 +4,7 @@ Only noting significant user-visible or major API changes, not internal code cle

## 1.9 (upcoming)

* [JENKINS-28131](https://issues.jenkins-ci.org/browse/JENKINS-26860): pass NODE_NAME into node{}.
* [JENKINS-26860](https://issues.jenkins-ci.org/browse/JENKINS-26860): added _Execute concurrent builds if necessary_ option for Workflow projects.
* [JENKINS-28756](https://issues.jenkins-ci.org/browse/JENKINS-28756): dropdown for _General SCM_ step incorrectly listed SCMs not compatible with Workflow.

@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright 2015.
* Copyright 2015 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,8 +24,6 @@

package org.jenkinsci.plugins.workflow;

import hudson.slaves.DumbSlave;

import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Rule;
@@ -41,17 +39,26 @@
@Rule public JenkinsRule r = new JenkinsRule();

/**
* Verifies if NODE_NAME environment variable is available in a slave node.
* Verifies if NODE_NAME environment variable is available on a slave node and on master.
*
* @throws Exception
*/
@Test public void areAvailable() throws Exception {
r.createSlave("node-test", null, null);
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "workflow-test");
DumbSlave s = r.createSlave("node-test", null, null);
s.getComputer().connect(false).get();

p.setDefinition(new CpsFlowDefinition("node('node-test') { echo \"My name is ${env.NODE_NAME}\" }"));
r.assertLogContains("My name is node-test", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
p.setDefinition(new CpsFlowDefinition(
"node('master') {\n" +
" echo \"My name on master is ${env.NODE_NAME}\"\n" +
"}\n"
));
r.assertLogContains("My name on master is master", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));

p.setDefinition(new CpsFlowDefinition(
"node('node-test') {\n" +
" echo \"My name on a slave is ${env.NODE_NAME}\"\n" +
"}\n"
));
r.assertLogContains("My name on a slave is node-test", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
}
@@ -44,7 +44,6 @@
import jenkins.util.Timer;

import org.acegisecurity.Authentication;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.durabletask.executors.ContinuableExecutable;
import org.jenkinsci.plugins.durabletask.executors.ContinuedTask;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
@@ -63,6 +62,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;


public class ExecutorStepExecution extends AbstractStepExecutionImpl {

@Inject(optional=true) private transient ExecutorStep step;
@@ -429,6 +429,8 @@ AccessControlled accessControlled() {
EnvVars env = computer.getEnvironment();
env.overrideAll(computer.buildEnvironment(listener));
env.put(COOKIE_VAR, cookie);
// TODO: Copied from https://github.com/jenkinsci/jenkins/blob/9c443c8d5bafd63fce574f6d0cf400cd8fe1f124/core/src/main/java/jenkins/model/CoreEnvironmentContributor.java#L59
// TODO: It is interesting to add NODE_LABELS and EXECUTOR_NUMBER
if (exec.getOwner() instanceof MasterComputer) {
env.put("NODE_NAME", "master");
} else {

0 comments on commit a7abe6c

Please sign in to comment.