Downstream Jenkins project gets wrong upstream run

2020-04-16 19:35发布

I'm having a problem with a Jenkins build pipeline. All jobs after the first one are parameterized with the "Run Parameter" of the first job. By default, this should reference the most recent stable build of the first job. Each subsequent job uses the "Run Parameter" of the first job to access saved artifacts from the first job. Each subsequent job triggers the next job of the pipeline as a parameterized build and passes the aforementioned "Run Parameter". The first job of the pipeline triggers the second job as a simple (i.e., not parameterized) build.

Here's a screenshot of the relevant configuration of a downstream job: enter image description here

My problem is that the job number in the "Run Parameter" isn't the job number of the first job of the pipeline. Instead, it's the job number of the first job of the previous pipeline. Thus, if the first job is on build #11, then all subsequent job of that pipeline will access the archive of build #10 of the first job.

How can I get the subsequent jobs of the pipeline to access the archive directory of the first job of the pipeline?

2条回答
何必那么认真
2楼-- · 2020-04-16 19:49

I discovered the answer. Apparently, the reason the downstream job was using the artifacts from the upstream job of the previous pipeline was because I had set the "Run Parameter" filter in the configuration of the downstream job to "Stable Builds Only". Setting this filter to "All Builds" results in correct behavior.

It's as if Jenkins doesn't consider an upstream job to be stable when it's starting another build in its post-build section.

查看更多
Animai°情兽
3楼-- · 2020-04-16 19:49

Quote: "By default, this should reference the most recent stable build of the first job."

Do you mean the last successful build of the Top job. Since in that case there might be a case where the last successful build of the top job was #7 and current build is #11. So you want the downstream jobs to look for #7 and not #10.

If that is the case then I will suggest putting a groovy build step. Install the groovy plugin for that. But before that test the script.

Open: YourJenkinsServerURL/script

Run this script.

def tmp = hudson.model.Hudson.instance
def myJobName="YourTopJobName";

tmp.getItems(hudson.model.Job).each {job ->
if(job.displayName == myJobName)
   {
        println(job.getLastSuccessfulBuild())
    }  
}

In groovy you can access and set an environment variable (injected via envInject plugin maybe) to this last successful build number and then pass on this variable to downstream job.

If that is not the case then I will suggest use Nant Script. Use "int::parse()" to convert the string format build number to integer. Decrement the value and then pass on the value to the downstream job.

查看更多
登录 后发表回答