Created
October 15, 2015 20:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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