Reputation: 323
I am executing ansible playbook from Jenkins scripted pipeline and I need help in capturing ansible playbook status (success/failed).
sh "ansible-playbook -i <args>"
PLAY RECAP *********************************************************************
serverName : ok=4 changed=0 unreachable=0 failed=1
[Pipeline] End of Pipeline
Finished: SUCCESS
In the above example, I have 1 failure but Jenkins job status is SUCCESS. How can I change the Jenkins job status to FAIL when playbook has at least 1 failure?
Upvotes: 1
Views: 2412
Reputation: 33231
sh "ansible-playbook -i <args>"
I would guess the shell block is not set to set -e
and thus, like most shell scripts, it does not consider a failed command to be a failure of the script as a whole. A grave antipattern, IMHO, but easily the majority of the scripts I've seen
So, I believe sh "set -e; ansible-playbook -i ..."
will straighten that out, or (in theory) you can use exec
since that is the only command present, and thus the failure of ansible-playbook is the failure of that shell: sh "exec ansible-playbook -i ..."
Upvotes: 1