Nab*_*Nab 4 groovy jenkins jenkins-plugins jenkins-pipeline
我在我的管道中使用了一个输入步骤,如下所示:
input(
message : "some message",
parameters: [
[$class: 'ChoiceParameterDefinition',
choices: string ,
description: 'description',
name:'input'
]
]
)
Run Code Online (Sandbox Code Playgroud)
我想使用我配置的名称输入来获取像 ${input} 这样的输入中的值,但它不起作用。我也试着把它放在一个像这样的 var 中:
def reg = input : messages : "", paramaters: [...]
Run Code Online (Sandbox Code Playgroud)
但它也不起作用,所以我不明白我如何获得用户选择的参数并且在 do 中没有找到如何做。
问候,
使用时ChoiceParameterDefinition记得将选项定义为以\n. 您可以将input(...)逐步返回的值分配给变量并在以后使用它。看看下面的例子:
node {
stage('Test') {
def reg = input(
message: 'What is the reg value?',
parameters: [
[$class: 'ChoiceParameterDefinition',
choices: 'Choice 1\nChoice 2\nChoice 3',
name: 'input',
description: 'A select box option']
])
echo "Reg is ${reg}"
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我定义了一个带有 3 个选项的选择。当我运行这个管道时,我得到这个弹出窗口来选择三个选项之一:
我选择第一个,管道完成以下控制台输出:
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] input
Input requested
Approved by admin
[Pipeline] echo
Reg is Choice 1
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Run Code Online (Sandbox Code Playgroud)
尝试使用此代码:
def userInput = input(id: 'userInput', message: 'some message', parameters: [
[$class: 'ChoiceParameterDefinition', choices: string, description: 'description', name:'input'],
])
VARAIBLE = userInput
Run Code Online (Sandbox Code Playgroud)
这是为我工作。如果您需要添加更多ChoiceParameterDefinition代码,则应如下所示:
def userInput = input(id: 'userInput', message: 'some message', parameters: [
[$class: 'ChoiceParameterDefinition', choices: string, description: 'description1', name:'input1'],
[$class: 'ChoiceParameterDefinition', choices: string, description: 'description2', name:'input2'],
])
VARAIBLE1 = userInput['input1']
VARAIBLE2 = userInput['input2']
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5819 次 |
| 最近记录: |