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

make additional tests compatible with Jenkins 2.307 #169

Merged
merged 2 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -809,7 +809,7 @@ private final class PlaceholderExecutable implements ContinuableExecutable, Acce
env.put(COOKIE_VAR, cookie);
// Cf. CoreEnvironmentContributor:
if (exec.getOwner() instanceof MasterComputer) {
env.put("NODE_NAME", "master");
env.put("NODE_NAME", node.getSelfLabel().getName()); // mirror https://github.com/jenkinsci/jenkins/blob/89d334145d2755f74f82aad07b5df4119d7fa6ce/core/src/main/java/jenkins/model/CoreEnvironmentContributor.java#L63
Copy link
Collaborator Author

@car-roll car-roll Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from #168

} else {
env.put("NODE_NAME", label);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ private static class Decorator extends LauncherDecorator implements Serializable
CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), c);
j.createSlave("remote", null, null);
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
String builtInNodeLabel = j.jenkins.getSelfLabel().getName(); // compatibility with 2.307+
p.setDefinition(new CpsFlowDefinition(
"node('master') {\n" +
"node('" + builtInNodeLabel + "') {\n" +
" sh 'pwd'\n" +
"}\n" +
"node('remote') {\n" +
Expand Down Expand Up @@ -499,10 +500,11 @@ private Object writeReplace() {
assumeFalse(Functions.isWindows()); // TODO create Windows equivalent
j.createSlave("remote", null, null);
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
String builtInNodeLabel = j.jenkins.getSelfLabel().getName(); // compatibility with 2.307+
p.setDefinition(new CpsFlowDefinition(
"node('master') {\n" +
"node('" + builtInNodeLabel +"') {\n" +
" markUp {\n" +
" sh 'echo hello from master'\n" +
" sh 'echo hello from " + builtInNodeLabel + "'\n" +
" }\n" +
"}\n" +
"node('remote') {\n" +
Expand All @@ -518,9 +520,9 @@ private Object writeReplace() {
b.getLogText().writeRawLogTo(0, System.err);
StringWriter w = new StringWriter();
b.getLogText().writeHtmlTo(0, w);
assertThat("a ConsoleNote created in the master is trusted", w.toString(), containsString("<b>hello</b> from master"));
assertThat("a ConsoleNote created in the " + builtInNodeLabel + " is trusted", w.toString(), containsString("<b>hello</b> from " + builtInNodeLabel));
assertThat("but this one was created in the agent and is discarded", w.toString(), containsString("hello from agent"));
assertThat("however we can pass it from the master to agent", w.toString(), containsString("<b>hello</b> from halfway in between"));
assertThat("however we can pass it from the " + builtInNodeLabel + " to agent", w.toString(), containsString("<b>hello</b> from halfway in between"));
} finally {
DurableTaskStep.USE_WATCHING = false;
}
Expand Down Expand Up @@ -636,8 +638,9 @@ private static final class HelloNote extends ConsoleNote<Run<?, ?>> {
j.showAgentLogs(s, logging);
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.addProperty(new ParametersDefinitionProperty(new BooleanParameterDefinition("WATCHING", false, null)));
String builtInNodeLabel = j.jenkins.getSelfLabel().getName(); // compatibility with 2.307+
p.setDefinition(new CpsFlowDefinition(
"['master', 'remote'].each {label ->\n" +
"['" + builtInNodeLabel + "', 'remote'].each {label ->\n" +
" node(label) {\n" +
" withCredentials([usernameColonPassword(variable: 'USERPASS', credentialsId: '" + credentialsId + "')]) {\n" +
" sh 'set +x; echo \"with final newline node=$NODE_NAME watching=$WATCHING\"'\n" +
Expand All @@ -650,7 +653,7 @@ private static final class HelloNote extends ConsoleNote<Run<?, ?>> {
for (boolean watching : new boolean[] {false, true}) {
DurableTaskStep.USE_WATCHING = watching;
String log = JenkinsRule.getLog(j.assertBuildStatusSuccess(p.scheduleBuild2(0, new ParametersAction(new BooleanParameterValue("WATCHING", watching)))));
for (String node : new String[] {"master", "remote"}) {
for (String node : new String[] {builtInNodeLabel, "remote"}) {
for (String mode : new String[] {"with", "missing"}) {
errors.checkThat(log, containsString(mode + " final newline node=" + node + " watching=" + watching));
}
Expand Down