Jenkins阶段参数化输入
Jenkins parameterized input in stage
我知道如何使用 parameters
指令为整个管道请求用户输入。现在我希望能够请求特定阶段内的用户输入,并能够在该阶段内访问该值。这是我的管道:
pipeline {
agent none
stages {
stage('Stage 1') {
when{
beforeAgent true
expression {
timeout (time: 30, unit: "SECONDS"){
input message: 'Should we continue?', ok: 'Yes',
parameters:[[
$class: 'ChoiceParameterDefinition',
choices: ['Stable release', 'SNAPSHOT'],
description: 'Which Version?',
name: 'version'
]]
}
return true
}
}
agent any
steps {
echo 'Checking dependencies ...'
echo "${params}"
}
}
}
}
在此管道中,我能够提示用户在 稳定版本 和 SNAPSHOT 之间进行选择 Stage 1阶段。但是我无法使用 ${params.version}
访问此变量。有什么解决办法吗?
我设法解决了这个问题并读取了用户在以下管道中选择的输入:
def version //define a global variable for the whole pipeline.
pipeline {
agent none
stages {
stage('Stage 1') {
when{
beforeAgent true
expression {
timeout (time: 30, unit: "SECONDS"){
//Assign the variable here.
version = input message: 'Should we continue?', ok: 'Yes',
parameters:[[
$class: 'ChoiceParameterDefinition',
choices: ['Stable release', 'SNAPSHOT'],
description: 'Which Version?',
name: 'v'
]]
}
return true
}
}
agent any
steps {
// And finally access it.
echo "${version}"
}
}
}
}
我知道如何使用 parameters
指令为整个管道请求用户输入。现在我希望能够请求特定阶段内的用户输入,并能够在该阶段内访问该值。这是我的管道:
pipeline {
agent none
stages {
stage('Stage 1') {
when{
beforeAgent true
expression {
timeout (time: 30, unit: "SECONDS"){
input message: 'Should we continue?', ok: 'Yes',
parameters:[[
$class: 'ChoiceParameterDefinition',
choices: ['Stable release', 'SNAPSHOT'],
description: 'Which Version?',
name: 'version'
]]
}
return true
}
}
agent any
steps {
echo 'Checking dependencies ...'
echo "${params}"
}
}
}
}
在此管道中,我能够提示用户在 稳定版本 和 SNAPSHOT 之间进行选择 Stage 1阶段。但是我无法使用 ${params.version}
访问此变量。有什么解决办法吗?
我设法解决了这个问题并读取了用户在以下管道中选择的输入:
def version //define a global variable for the whole pipeline.
pipeline {
agent none
stages {
stage('Stage 1') {
when{
beforeAgent true
expression {
timeout (time: 30, unit: "SECONDS"){
//Assign the variable here.
version = input message: 'Should we continue?', ok: 'Yes',
parameters:[[
$class: 'ChoiceParameterDefinition',
choices: ['Stable release', 'SNAPSHOT'],
description: 'Which Version?',
name: 'v'
]]
}
return true
}
}
agent any
steps {
// And finally access it.
echo "${version}"
}
}
}
}