2016-03-15 61 views
3

我想一個詹金斯管道運行時從乳寧鎖定一些其他的工作,
我一直在試圖使用排除-插件油門併發builds-插件
具有這種結構:詹金斯管道節流其他工作

node(){ 
    stage "test" 
    allocate('test') 
    sleep time: 15, unit: 'MINUTES' 
    sh "echo 'yes'" } 

@NonCPS 
def allocate(String resource){ 

    throttle = new hudson.plugins.throttleconcurrents.ThrottleJobProperty(
    maxConcurrentPerNode=1, 
    maxConcurrentTotal=1, 
    categories = [resource], 
    throttleEnabled=true, 
    throttleOption="category", 
    matrixOptions=null 
    ) 
    throttle.setOwner() 
    throttle = null 
    return true 
} 

但它似乎並不做任何事情...
我開始用Groovy的流水線插件,我通過無力塊油門其他作業
謝謝你的幫助!

回答

1

對於那些誰是在同樣的掙扎,
您可以使用此插件:使用這個分支https://github.com/jenkinsci/lockable-resources-plugin
https://github.com/jenkinsci/lockable-resources-plugin/pull/25

我不知道這是否會合並一些日子,但MR是完全可用,並且可以像使用:

echo 'Starting' 
lock('my-resource-name') { 
    echo 'Do something here that requires unique access to the resource' 
    // any other build will wait until the one locking the resource leaves this block 
} 
echo 'Finish' 
+0

看起來像分支合併爲主:) –

+0

請記住,鎖定資源插件阻止作業執行之後,節點/執行器已被分配。 – deadmoto