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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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