从正在执行的Shell中终止Jenkins作业 [英] Aborting a Jenkins job from within the executing shell

查看:911
本文介绍了从正在执行的Shell中终止Jenkins作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先介绍一下上下文:

当前,我有一个Jenkins作业设置来运行perl脚本,而该脚本又会在运行的任何计算机上构建源代码.

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

根据我对Jenkins行为的观察,如果我从UI中止了一个正在运行的Jenkins作业,则我的Perl脚本的所有相关线程(单线程或并行线程)都会在相应的从属计算机上被杀死.

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.

现在,我想复制该行为,即在构建步骤中中止Jenkins作业IF,我的脚本会产生一些错误.不幸的是,我无法轻松地修改或更新正在启动的perl脚本(我不是所有者),所以我必须找到一个解决方案,如果可能的话,当然需要对perl脚本本身进行最少的修改.

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.

我可以自动执行这种行为吗?也许通过扫描perl脚本的日志以查找错误?还是类似的东西?

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.

谢谢.

我找到了一个有趣的解决方案,实际上可以中止这项工作.通过运行以下命令:

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.

推荐答案

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.

免责声明:我已进行了此更改,我应该更新Wiki

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

这篇关于从正在执行的Shell中终止Jenkins作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆