我有一个用于db回滚脚本的Jenkins作业,该脚本使用每个环境的选项参数(使用NodeLabel参数插件)。
我希望这些作业能够同时运行,但仅适用于不同的环境。
"必要时执行并发构建"已启用。
E.g。如果作业正在运行LIVE,请允许某人再次为TEST运行作业(这可行)。但是,如果LIVE已经在运行并且有人再次为LIVE运行作业,则不要运行。
这个插件似乎符合我的需要,但没有显示在Manage Jenkins的可用插件列表中。
https://wiki.jenkins-ci.org/display/JENKINS/Concurrent+Run+Blocker+Plugin
还有其他方法吗?
答案 0 :(得分:1)
现有的Jenkins插件有一个解决方案:
☑此版本已参数化
NODE
JOB
... the jobs' names you'd like to start with this ...
<强>构建强>
Not
Execute Shell
#!/bin/bash +x -e
# Bash 4 needed for associative arrays
# From http://stackoverflow.com/questions/37678188/jenkins-stop-concurrent-job-with-same-parameter
echo ' Build --> Conditional step (single) --> Execute Shell'
echo " Checking whether job '$JOB' runs on node '$NODE'"
echo ' Creating array'
declare -A computers
# ------------------------------------------------------------------------
# Declare your nodes and their executors here as mentioned, for instance,
# in the API URI 'http://<jenkins>/computer/(master)/executors/0/api/xml':
computers=( # ^^^^^^ ^
[master]="0 1 2 3"
[slave]="0 1"
)
# Note: Executor indices DO NOT conform to the numbers in Jenkins'
# Build Executor Status UI.
# ------------------------------------------------------------------------
echo " Checking executors of node '$NODE'"
for computer in ${!computers[@]} ; do
for executorIdx in ${computers[$computer]} ; do
if [[ $computer == $NODE ]] ; then
if [[ "$computer" == "master" ]] ; then
node="(${computer})"
else
node=$computer
fi
url="${JENKINS_URL}/computer/${node}/executors/${executorIdx}/api/xml?tree=currentExecutable\[url\]"
echo " $url"
xml=$(curl -s $url)
#echo $computer, $executorIdx, $xml
if [[ "$xml" == *"/job/${JOB}"* ]] ; then
echo " Job '$JOB' is already building on '$computer' executor index '$executorIdx'"
echo ' Exiting with 1'
exit 1
fi
fi
done
done
echo ' Exiting with 0'
Set the build result
Aborted
Current build status
Trigger/call build on other projects
$JOB
[忽略错误消息] NODE
[或您在下游工作中如何称呼] $NODE