2017-02-14 66 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." 
    } 
}