Search code examples
jenkinsjenkins-pipelinedevopsjenkins-workflow

Jenkins: Mark build as success if the last step succeded even if a previous step was unstable


I've in jenkins a flow like this:

Wrapper Job1

  • Trigger Job2
  • (Conditionally) if the job 2 is unstable it triggers the Job3

Below you can see JOB1 (wrapper) configuration pics:

JOB2 trigger configuration :

JOB2 trigger configuration

JOB3 conditional trigger configuration

JOB3 conditional trigger configuration

Now, to give you a little bit of context:

I'm running tests with selenium and cucumber, these tests can randomly fail and if they fail, the job2 is marked unstable (if not the wrapper just finish with success status), in case the job2 fails will be triggered the job3, this is a "RERUN FAILED TESTS" task, then obviously in the case this last will be completed with success I want the wrapper to be marked as SUCCESS.

This should be really easy, but it's not working, below the wrapper (JOB1) jenkins job log:

FIRST STEP (JOB2) UNSTABLE BECAUSE SOME TESTS FAILED:

Waiting for the completion of REM_Parallel_Tag_Sub_Runner
REM_Parallel_Tag_Sub_Runner #9 completed. Result was UNSTABLE
Build step 'Trigger/call builds on other projects' changed build result    
to **UNSTABLE**

IF THE JOB2 IS UNSTABLE THE WRAPPER TRIGGER THE JOB 3:

[Current build status] check if current [UNSTABLE] is worse or equals then
[UNSTABLE] and better or equals then [UNSTABLE]
Run condition [Current build status] enabling perform for step [BuilderChain]
Waiting for the completion of REM_Parallel_Sub_ReRuns

THE JOB 3 SUCCEEDED, THIS MEANT THAT THE TESTS THAT WERE FAILING NOW ARE SUCCEEDING, AND I WANT THAT THIS STEP UPDATE THE JOB1 FROM UNSTABLE TO SUCCESS, IT SHOULD BE A NORMAL BEHAVIOUR

 REM_Parallel_Sub_ReRuns #6 completed. Result was SUCCESS
 [CucumberReportPublisher] Compiling Cucumber Html Reports ...
 [CucumberReportPublisher] Copying all json files from: /PATH/workspace  /TiaCukes to reports directory: /PATH/cucumber-html-reports
 [CucumberReportPublisher] there were no json results found in: /u01/app/build/jenkins/jobs/REM_Parallel_Tag_Runner_Orchestrator/builds/9/cucumber-html-reports
 Started calculate disk usage of build
 Finished Calculation of disk usage of build in 0 seconds
 Started calculate disk usage of workspace
 Finished Calculation of disk usage of workspace in 0 seconds
 No emails were triggered.
 Warning: you have no plugins providing access control for builds, so    falling back to legacy behavior of permitting any downstream builds to be triggered

 Finished: UNSTABLE

AS YOU CAN SEE THE BUILD STATUS HAS NOT BEEN UPDATED, EVEN IF THE LAST TRIGGERED STEP SUCCEEDED, THE BUILD STATUS REMAINS UNSTABLE

How can i fix it? Should not be so hard goal to accomplish!

Thanks a lot!


Solution

  • Resolved with the use of variables set by Parameterized Trigger Plugin:

    https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin

    Pics below:

    JOB2 trigger configuration: JOB2 trigger configuration

    JOB3 conditional trigger configuration: enter image description here

    Feel free to ask about details