Jenkins 2.x - Pipeline(DSL) - Build failed but all stages are green

3,769 views
Skip to first unread message

thomas....@teamaol.com

unread,
Jul 21, 2016, 5:53:41 AM7/21/16
to Jenkins Users
We are working with Jenkins 2.13 the moment.
We have a ci/cd pipeline with all stages green but the build itself is red.

From the log I cannot see anything which gives me a hint.
Also all deployed stuff is fine and the final slack notification were also fine!

Every "sh" call is wrapped by the try ... catch ... throw ... so if there would
be an error the pipeline should stop at the stage where the error appears.

I wrote manually a jenkinsfile but ... as you can guess ... all fine.

I didn't found a way to check the build state. When is this set?
Can I do an echo of current state so I could add some output?

currentBuild.result prints null, so obviously this is not used.
Any help, proposes?

Kind regards,
Thomas

Thomas Zoratto

unread,
Jul 21, 2016, 6:00:15 AM7/21/16
to jenkins...@googlegroups.com
currentBuild.result is writable

try to set it to 'SUCCESS' when before your pipeline reaches the end

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/13fa2d82-4e53-40df-a9a6-d6d2f020b2b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

thomas....@teamaol.com

unread,
Jul 21, 2016, 6:07:43 AM7/21/16
to Jenkins Users
Will give it a try ...

thomas....@teamaol.com

unread,
Jul 21, 2016, 6:17:28 AM7/21/16
to Jenkins Users
When I do this ... currentBuild.result = "FAILURE" for a small test pipeline job then the build fails also the stages are green.
Exactly the problem I explained. When setting to "SUCCESS" all is fine. So obvious there is anything adjusting the state wrongly.

Is there a way where I can check the success state after each operation?
(as mentioned ... echo currentBuild.result prints null)

Thomas Zoratto

unread,
Jul 21, 2016, 6:24:43 AM7/21/16
to jenkins...@googlegroups.com
You want to do something like :

try {
currentBuild.result = "SUCCESS"
//do your stuff, stages etc.
} catch (err) {
currentBuild.result = "FAILURE"
throw err
}

(Of course you’ll have to adjust this to your needs)

This way the build will be green if all the stages are green and it will be red if a stage fails.

Is this what you’re looking for ?


thomas....@teamaol.com

unread,
Aug 2, 2016, 6:39:18 AM8/2/16
to Jenkins Users
I still have the issue with a succeeded pipeline that shows red.
Even when I say: currentBuild.result = "SUCCESS" ... at the end
No trace all steps are executed fine .... just the state is wrong.

Using now Jenkins 2.14

Baptiste Mathus

unread,
Aug 2, 2016, 7:42:58 AM8/2/16
to jenkins...@googlegroups.com

Maybe you could share a gist of your script, showing the issue you're having and what you want/expect? Will probably be more efficient than just speaking about that code?


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

thomas....@teamaol.com

unread,
Aug 12, 2016, 8:46:03 AM8/12/16
to Jenkins Users, m...@batmat.net
All parts of the script are like this:

try {
   
// do something
} catch(all) {
   
def message="...."
    notifySlack(message)
   
throw new Exception(message)
}

// finally
notifySlack("Done!")
currentBuild.result = "SUCCESS"


I never see a message from the "catch" but I see the "Done!". All processes of the pipeline are fine:
 - war file created
 - Docker container/images created and/or deleted
 - Upload of things in S3 bucket
 - ...

The build is red. To be more precise ... the stage show in deep red is this one:

 stage 'Remove Build Image'
            try {
                removeBuildImage(WORKSPACE)
            } catch (all) {
                def message="Failed to remove build image!"
                notifySlack(message)
                // Does not make sense to continue
                throw new Exception(message)
            }


The slack message is not shown ... and in the logs:

06:58:21 Deleted: sha256:aa4e7c1557f3bfab99c3e233d6be5647061d81fdc5b570921eec0d7cc033c2dd
06:58:21 Deleted: sha256:6a74d75c87b71c9d8e6e6988baf48cc2ed2b7fb6b4ea87cb5d602c4b224a0483
06:58:21 remove_image.sh :: Success: Docker build image removed

That's the last "echo" of that script. In the Jenkins file the function looks like this

  4 // Remove the Docker image for the build.                                                                     
  5 def removeBuildImage(WORKSPACE) {                                                                             
  6     sh "WORKSPACE=$WORKSPACE $WORKSPACE/cicd/scripts/remove_image.sh build"                                   
  7 }        

I don't see the moment how to proceed. If I could adjust the pipeline to debug mode that it does print
its state so I could see at which point it "believes" that something has been going wrong ...

Any ideas what I could do?

Prabhuanand Sivashanmugam

unread,
Dec 10, 2016, 11:11:55 PM12/10/16
to Jenkins Users, m...@batmat.net
Exactly in the same position.. trying to find a solution

-Prabhu

Prabhuanand Sivashanmugam

unread,
Dec 11, 2016, 12:49:38 AM12/11/16
to Jenkins Users, m...@batmat.net
Okay, i fixed it for myself. One of the intermediate steps failed for me.

I was trying to archive the jar file from a different folder than what I config'ed. Apparently, its something to deal with the work space area (either we delete the workspace or something been changed)



You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/Bu8GeYSqm1Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/71c4e1ff-850f-40a5-a7e8-09089e8d57d0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Thx / Prabhu
Reply all
Reply to author
Forward
0 new messages