How to handle failed jenkins build jobs with automated python script

  jenkins, jenkins-pipeline, python

I wrote a python script to kick off build jobs for all of our microservices. I am doing some testing and want to ensure I handle a job that occurs an error and fails somewhere in the deploy.jenkins file.

I basically just created another pipeline job for this deployment build script, call it manually from jenkins then it checks out from github, builds my docker container, then kicks off all the microservices that I want to deploy.

So for now to test, I added a sh "exit 1" in on of the microservices to fail one of the jobs and when it fails, it also fails my whole deploy job script. The other microservices continue to build, but my script also polls/tracks each job after they are kicked off until they are complete, with a goal in the future to write a teams webhook with status, so I’m missing all this once the script exits because of one failed build.

What’s the best way to handle a failed job without terminating my deployment script so it doesn’t exit and can continue polling the other build jobs?

Source: Python Questions

LEAVE A COMMENT