Some of the downstream builds might be configured for All, lastCompleted, lastSuccessful and others for lastStable. Multiple downstream builds might have different requirements. It would be better to have this config in one place, the downstream jobs, and not have to work around this change and require additional logic in the upstream build to determine what RunParameter to pass to the downstream job.
It worked as expected when the Run#getLastStableBuild used to be like:
public RunT getLastStableBuild() {
RunT r = getLastBuild();
while (r != null
&& (r.isBuilding() || r.getResult().isWorseThan(Result.SUCCESS)))
r = r.getPreviousBuild();
return r;
}
It no longer works after it was changed to use the Permalink
public RunT getLastStableBuild() {
return (RunT)Permalink.LAST_STABLE_BUILD.resolve(this);
}
The State.POST_PRODUCTION seems to be for this very scenario, where the build result is now final and it is now ok to trigger other builds as described in JENKINS-980
private static enum State {
/**
* Build is completed now, and the status is determined,
* but log files are still being updated.
*
* The significance of this state is that Jenkins
* will now see this build as completed. Things like
* "triggering other builds" requires this as pre-condition.
* See JENKINS-980.
*/
POST_PRODUCTION,
In the Run#execute method, I think we should update the PeepholePermalinks as soon as we change state and before we trigger fireCompleted on the listeners????
Currently the Permalinks are updated in a fireCompleted event on a listener, the same as triggering downstream jobs. But they seem to be updated after the other builds are triggered.
state = State.POST_PRODUCTION;
if (listener != null) {
try {
job.cleanUp(listener);
} catch (Exception e) {
handleFatalBuildProblem(listener,e);
}
RunListener.fireCompleted(this,listener);
listener.finished(result);
listener.closeQuietly();
}
It seems that you need an access not to the latest build, but to the build that triggered the downstream build.
If so, I know it can be resolved by adding RunParameter support to parameterized build plugin, but you may also consider using UpstreamCause to access to the upstream build.
For example, Copy Artifact plugin provides an option to retrieve artifacts from the upstream build that triggered that downstream build.