{
FreeStyleProject p = jenkins.getItemByFullName("upstream", FreeStyleProject.class);
assertNotNull(p);
FreeStyleBuild b = p.getLastBuild();
assertNotNull(b);
BuildInfoExporterAction action = b.getAction(BuildInfoExporterAction.class);
assertNotNull(action);
// action should contain following builds:
// downstream1#1
// downstream1#2
// downstream2#1
assertEquals(
Sets.newHashSet(
jenkins.getItemByFullName("downstream1", FreeStyleProject.class).getBuildByNumber(1),
jenkins.getItemByFullName("downstream1", FreeStyleProject.class).getBuildByNumber(2),
jenkins.getItemByFullName("downstream2", FreeStyleProject.class).getBuildByNumber(1)
),
new HashSet<AbstractBuild<?,?>>(action.getTriggeredBuilds())
);
EnvVars env = new EnvVars();
action.buildEnvVars(b, env);
lastReferenceValue = env.get(BuildInfoExporterAction.JOB_NAME_VARIABLE);
assertEquals("downstream1", lastReferenceValue);
b.save();
}
{
FreeStyleProject p = jenkins.getItemByFullName("upstream", FreeStyleProject.class);
assertNotNull(p);
FreeStyleBuild b = p.getLastBuild();
assertNotNull(b);
BuildInfoExporterAction action = b.getAction(BuildInfoExporterAction.class);
assertNotNull(action);
// action should contain following builds:
// downstream1#1
// downstream1#2
// downstream2#1
assertEquals(
Sets.newHashSet(
jenkins.getItemByFullName("downstream1", FreeStyleProject.class).getBuildByNumber(1),
jenkins.getItemByFullName("downstream1", FreeStyleProject.class).getBuildByNumber(2),
jenkins.getItemByFullName("downstream2", FreeStyleProject.class).getBuildByNumber(1)
),
new HashSet<AbstractBuild<?,?>>(action.getTriggeredBuilds())
);
EnvVars env = new EnvVars();
action.buildEnvVars(b, env);
assertEquals(lastReferenceValue, env.get(BuildInfoExporterAction.JOB_NAME_VARIABLE));
}
}