Jenkins工作流程检查作业是否正在运行或已计划 [英] Jenkins workflow check if job is running or schedulled
本文介绍了Jenkins工作流程检查作业是否正在运行或已计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过某些工作流脚本检查某项作业是否正在运行或计划中?
is it possible to check if some job is running or scheduled from some workflow script?
尽管使用阶段管理并发似乎足够了:
Although it may seems enough to manage concurrency using stages:
stage name: 'stageName', concurrency: 1
并在以下阶段运行构建:
and run builds in those stages like this:
build job: 'test-job', wait: false
可能是有人手动开始工作 test-job ,而我只是想在我的工作流程脚本中处理这种情况.例如,跳过构建或等待构建完成.
it may happen that someone started the job test-job manually and I just want to handle that situation in my workflow script. For example by skipping the build or waiting till the build is finished.
推荐答案
此方法适用于不使用 Groovy Sandbox 的流:
This works in flows that are not using Groovy Sandbox:
for (Project job : Hudson.getInstance().getProjects()) {
if (job.isBuilding() || job.isInQueue()) {
echo "${job.getName()}"
}
}
这篇关于Jenkins工作流程检查作业是否正在运行或已计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文