20
votes

I have a Jenkins job, that uses the pipeline mechanics. It has several steps. For understanding let's assume I have 3 stages. the first 2 run in parallel, the 3rd after them. Now depending on the result of the last build of stage 3 I want to do different thing. If stage 3 was previously successful, I want the result from stage 1, otherwise take stage 2 result. Is this possible to check? I don't get how to retrieve the last result of a stage, only did a similiar thing for last state of a job.

1
Can you elaborate what you mean with "pipeline mechanics"? Which plugin are you using? workflow? MultiJob? or just triggering downstream jobs? - Christian Goetze
Hard to tell for me, since I have no access to plugin settings. When I create a new Job it says: "Pipeline Orchestrates long-running activities that can span multiple build slaves. Suitable for building pipelines (formerly known as workflows) and/or organizing complex activities that do not easily fit in free-style job type." ... I thought this was now integrated into Jenkins w/o plugin. - Matthias
@Matthias - I have pretty same issue. So far I did not manage to access Stage Result directly, but good entry point is currentBuild.rawBuild global variable, which is available throughout your pipeline. It returns you a Run object, described here. You may then call smth like currentBuild.rawBuild.getPreviousSuccessfulBuild() and dig into jenkins API in order to somehow retrieve Stage results. Please also make sure, that an access to rawBuild is allowed in your Jenkins groovy sandbox. - Aleks
Since those are stages, not jobs - you should be able just to set a boolean flags that's available to all stages. From your description, it seems to be just one Jenkinsfile/Pipeline with some stages in it. Could you please post some code? - hakamairi
@BlazejChecinski Wow, actually it was as easy as to use some global variables that are available everywhere...now I feel dumb not trying it :D - Matthias

1 Answers

2
votes
  1. Write output from only succesfull job, no need to check then
  2. I've not heard stage status, you've to break your stages into separate jobs and then use 'job status'