2017-02-14 24 views
0

我們正在使用Lockable Resource Plugin來防止我們的某些作業部分同時運行。我希望允許作業啓動並使用「輸入步驟」收集輸入參數,然後排隊,同時等待任何阻塞鎖定清除,然後繼續。相反,我看到整個作業被阻止,並且不允許我輸入輸入,直到所有鎖定都被清除,即使我在鎖定塊之外有輸入步驟。使用鎖定插件在輸入步驟後排隊作業

我在做什麼錯?

下面是一個例子:

// Define an input step and capture the outcome from it. 
def outcome = input id: 'deployment', 
    message: 'Deployment Configuration', 
    ok: 'Deploy', 
    parameters: [ 
    [ 
     $class  : 'hudson.model.ChoiceParameterDefinition', choices: "development", 
     name  : 'stack', 
     description: 'select a stack to deploy' 
    ], 
    [ 
     $class  : 'hudson.model.ChoiceParameterDefinition', choices: "choice1\nchoice2", 
     name  : 'profile', 
     description: 'select a profile to deploy' 
    ], 
    ] 

def profile = "${outcome.get('profile')}" 
def stack = "${outcome.get('stack')}" 

echo "profile: ${profile}" 
echo "stack: ${stack}" 

// use lockable resource to prevent multiple jobs of the same project from running at the same time. 
lock(resource: "deployment") { 
    sh "echo running deployment script here." 
} 

回答

0

下面這篇文章Jenkins Pipeline: 「input」 step blocks executor 我能夠加入

stage('deploy') { 
} 

在我的塊來解決這個問題。例如。

// Define an input step and capture the outcome from it. 
def outcome = input id: 'deployment', 
    message: 'Deployment Configuration', 
    ok: 'Deploy', 
    parameters: [ 
    [ 
     $class  : 'hudson.model.ChoiceParameterDefinition', choices: "development", 
     name  : 'stack', 
     description: 'select a stack to deploy' 
    ], 
    [ 
     $class  : 'hudson.model.ChoiceParameterDefinition', choices: "choice1\nchoice2", 
     name  : 'profile', 
     description: 'select a profile to deploy' 
    ], 
    ] 

def profile = "${outcome.get('profile')}" 
def stack = "${outcome.get('stack')}" 

stage('deploy') { 
    echo "profile: ${profile}" 
    echo "stack: ${stack}" 

    // use lockable resource to prevent multiple jobs of the same project from running at the same time. 
    lock(resource: "deployment") { 
    sh "echo running deployment script here." 
    } 
}