Aborting a Jenkins job from within the executing s

2019-08-27 15:16发布

First some context:

Currently I have a Jenkins job setup to run a perl script, that in turns builds source code on whatever machine it is running.

From my observation of the Jenkins behaviour, if I abort a running Jenkins job from the UI all the associated threads (single or parallel) of my perl script are killed on the respective slave machine.

Now what I would like to replicate that behaviour ie abort a Jenkins job IF during my build step my script produces some errors. Unfortunately I am not able to easily modify or update the perl script that is being launched (I am not the owner) so I have to find a solution that would need minimal modification the perl script itself, if possible of course.

The reason I need it to be aborted is because we do not want to build any down stream dependencies after the area/repos/location where an error has been produced.

Would I be able to automate this type of behaviour? Maybe by scanning the logs of the perl script in search of error? Or something of the sort?

Any leads would be much appreciated.

Do let me know if more information/clarification is needed.

Thanks.

EDIT:

I found an interesting solution that actually aborts the job. By running the following command:

curl --request POST  -u <username>:<password> "%JENKINS_URL%/job/%JOB_NAME%/lastBuild/stop"

Of course, I would now have to figure a way to launch this command whenever any errors are found in the areas that are currently being compiled.

I feel like I am half way though.

1条回答
Fickle 薄情
2楼-- · 2019-08-27 16:07

There is the xshell plugin which can parse the log file as it goes and can fail the job if it hits a regex (or takes too long). This plugin replaces the shell step.

enter image description here

Disclaimer: I put this change in and I should update the wiki

查看更多
登录 后发表回答