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

Commit

Permalink
[JENKINS-28131] Improving the test and adding some inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
recena committed Jun 29, 2015
1 parent 6a64190 commit a7abe6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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.

Expand Down
@@ -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
Expand All @@ -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;
Expand All @@ -41,17 +39,26 @@ public class EnvWorkflowTest {
@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)));
}
}
Expand Up @@ -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;
Expand All @@ -63,6 +62,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;


public class ExecutorStepExecution extends AbstractStepExecutionImpl {

@Inject(optional=true) private transient ExecutorStep step;
Expand Down Expand Up @@ -429,6 +429,8 @@ private final class PlaceholderExecutable implements ContinuableExecutable {
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 {
Expand Down

0 comments on commit a7abe6c

Please sign in to comment.