2016-06-07 112 views
1

对于使用每个环境的选择参数(使用NodeLabel参数插件)的数据库回滚脚本,我有一个Jenkins作业。Jenkins - 停止具有相同参数的并发作业

我希望作业能够同时运行,但仅适用于不同的环境。

“如果需要执行并发构建”已启用。

E.g.如果作业正在运行LIVE,请允许某人再次为TEST运行作业(此作品)。但是,如果LIVE已经在运行,并且有人再次为LIVE运行作业,则不要运行。

这个插件似乎符合我的需求,但没有显示在Manage Jenkins的可用插件列表中。

https://wiki.jenkins-ci.org/display/JENKINS/Concurrent+Run+Blocker+Plugin

是否有解决此其他方法吗?

回答

1

有与现有詹金斯插件的解决方案:

  • 创建自由泳项目命名为喜欢入门并发完全建立在节点
  • ☑此版本是参数

    • 节点   [NodeLabel Parameter Plugin]
      • 名称:NODE
    • 选择参数
      • 名称:JOB
      • 选项:... the jobs' names you'd like to start with this ...
  • 生成

 

#!/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   [或你怎么称呼它在你的下游作业(S)]
          • 节点:$NODE
+0

谢谢你带我注意到的条件构建插件,这正是我所需要的。 – adjuzy

相关问题