[英]Jenkins parameterized input in stage
I know how to request for the user input for the whole pipeline using parameters
directive.我知道如何使用parameters
指令请求整个管道的用户输入。 Now i want to be able to request for the user input inside a specific stage and be able to access that value inside the stage.现在我希望能够在特定阶段内请求用户输入,并能够在阶段内访问该值。 Here's my pipeline:这是我的管道:
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}"
}
}
}
}
In this pipeline I'm able to prompt the user to choose between Stable release and SNAPSHOT inside Stage 1 stage.在这个管道中,我能够提示用户在第 1阶段的稳定版本和SNAPSHOT之间进行选择。 However I'm not able to access this variable using ${params.version}
.但是我无法使用${params.version}
访问这个变量。 Any ideas how to solve this?任何想法如何解决这个问题?
I managed to work around the problem and read the input chosen by user as in the following pipeline:我设法解决了这个问题并读取了用户选择的输入,如下面的管道:
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}"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.