Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added EXECUTOR_COUNT to environment variables #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ private final class PlaceholderExecutable implements ContinuableExecutable, Acce
env.put("NODE_NAME", label);
}
env.put("EXECUTOR_NUMBER", String.valueOf(exec.getNumber()));
env.put("EXECUTOR_COUNT", String.valueOf(computer.countExecutors()));
env.put("NODE_LABELS", Util.join(node.getAssignedLabels(), " "));

synchronized (runningTasks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ public class EnvWorkflowTest {
r.assertLogContains("My number on a slave is 0", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

/**
* Verifies if EXECUTOR_COUNT environment variable is set
*/
@Test public void isExecutorCountAvailable() throws Exception {
r.jenkins.setNumExecutors(2);
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_COUNT}\"\n" +
"}\n"
));
r.assertLogContains("My number on master is 2", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));

p.setDefinition(new CpsFlowDefinition(
"node('node-test') {\n" +
" echo \"My number on a slave is ${env.EXECUTOR_COUNT}\"\n" +
"}\n"
));
r.assertLogContains("My number on a slave is 1", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

@Issue("JENKINS-33511")
@Test public void isWorkspaceAvailable() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
Expand Down