Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #280 from bss/JENKINS-31391-Executor-number
Browse files Browse the repository at this point in the history
Add EXECUTOR_NUMBER to build env
  • Loading branch information
jglick committed Dec 18, 2015
2 parents 1d8a2a4 + 15de12e commit 5bf7826
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -7,6 +7,7 @@ Only noting significant user changes, not internal code cleanups and minor bug f
* [JENKINS-26126](https://issues.jenkins-ci.org/browse/JENKINS-26126) (partial): introspect Workflow steps to generate static reference documentation (link from _Snippet Generator_). Planned to be used for IDE auto-completion as well.
* [JENKINS-31897](https://issues.jenkins-ci.org/browse/JENKINS-31897): parameters with default values may now be omitted from the `parameters` option to the `build` step.
* [JENKINS-31909](https://issues.jenkins-ci.org/browse/JENKINS-31909): form validation warning about Groovy syntax errors was broken in 1.11.
* [JENKINS-31391](https://issues.jenkins-ci.org/browse/JENKINS-31391): pass `EXECUTOR_NUMBER` into `node {}`.

## 1.12 (Dec 14 2015)

Expand Down
Expand Up @@ -43,7 +43,7 @@ public class EnvWorkflowTest {
*
* @throws Exception
*/
@Test public void areAvailable() throws Exception {
@Test public void isNodeNameAvailable() throws Exception {
r.createSlave("node-test", null, null);
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "workflow-test");

Expand All @@ -61,4 +61,29 @@ public class EnvWorkflowTest {
));
r.assertLogContains("My name on a slave is node-test", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}


/**
* Verifies if EXECUTOR_NUMBER environment variable is available on a slave node and on master.
*
* @throws Exception
*/
@Test public void isExecutorNumberAvailable() throws Exception {
r.createSlave("node-test", null, null);
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "workflow-test");

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

p.setDefinition(new CpsFlowDefinition(
"node('node-test') {\n" +
" echo \"My number on a slave is ${env.EXECUTOR_NUMBER}\"\n" +
"}\n"
));
r.assertLogContains("My number on a slave is 0", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
}
Expand Up @@ -34,7 +34,6 @@ node {
The following variables are currently unavailable inside a workflow script:
</p>
<ul>
<li><code>EXECUTOR_NUMBER</code></li>
<li><code>NODE_LABELS</code></li>
<li><code>WORKSPACE</code></li>
<!-- TODO when JENKINS-24141 fixed: SCM.all().each { e -> st.include(class:e.clazz, page:"buildEnv", optional:true) } -->
Expand Down
Expand Up @@ -422,6 +422,7 @@ private final class PlaceholderExecutable implements ContinuableExecutable {
} else {
env.put("NODE_NAME", label);
}
env.put("EXECUTOR_NUMBER", String.valueOf(exec.getNumber()));

synchronized (runningTasks) {
runningTasks.put(cookie, new RunningTask());
Expand Down

0 comments on commit 5bf7826

Please sign in to comment.