Skip to content

Commit

Permalink
[JENKINS-69935] Set correct NODE_NAME on controller (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite authored Dec 4, 2022
1 parent 9308163 commit 25453b8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Map<String, String> getJenkinsSystemEnvVars(boolean forceOnMaster)
if (computer != null) {
result = computer.getEnvironment().overrideAll(result);
if(computer instanceof MasterComputer) {
result.put("NODE_NAME", "master");
result.put("NODE_NAME", Jenkins.get().getSelfLabel().getName());
} else {
result.put("NODE_NAME", computer.getName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jenkinsci.plugins.envinject.service;

import java.util.Map;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.envinject.service.EnvInjectVariableGetter;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;

/**
* @author Mark Waite
*/
public class EnvInjectVariableGetterSystemTest {

@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();

@Issue("JENKINS-69795")
@Test
public void testSystemEnvVars() throws Exception {
boolean forceOnMaster = true;
Map<String, String> systemEnvVars = EnvInjectVariableGetter.getJenkinsSystemEnvVars(forceOnMaster);
assertThat(systemEnvVars, hasKey("NODE_NAME"));
assertThat("Wrong NODE_NAME value", systemEnvVars.get("NODE_NAME"), is(Jenkins.get().getSelfLabel().getName()));
assertThat(systemEnvVars, hasKey("NODE_LABELS"));
assertThat("Wrong NODE_LABELS value", systemEnvVars.get("NODE_LABELS"), is(Jenkins.get().getSelfLabel().getName()));
}
}

0 comments on commit 25453b8

Please sign in to comment.