Skip to content

Instantly share code, notes, and snippets.

@jglick
Created October 15, 2015 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jglick/0e6060522484d85f0e09 to your computer and use it in GitHub Desktop.
Save jglick/0e6060522484d85f0e09 to your computer and use it in GitHub Desktop.
demo of using currentBuild.rawBuild.parent to do lookups of sister jobs by name
@Test public void lookUpSister() {
r.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
MockFolder dir = r.j.createFolder("dir");
WorkflowJob ds = dir.createProject(WorkflowJob.class, "ds");
ds.setDefinition(new CpsFlowDefinition("echo 'ran downstream build'"));
r.j.assertBuildStatusSuccess(ds.scheduleBuild2(0));
WorkflowJob us = dir.createProject(WorkflowJob.class, "us");
us.setDefinition(new CpsFlowDefinition(
"def jobName = 'ds'\n" +
"getLogs(jobName)\n" +
"String getLogs (String jobName) {\n" +
" def job = Jenkins.instance.getItem(jobName, currentBuild.rawBuild.parent)\n" +
" echo job.getLastBuild().getLog()\n" +
"}"));
r.j.assertLogContains("ran downstream build", r.j.assertBuildStatusSuccess(us.scheduleBuild2(0)));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment