I have configured jenkins pipeline which has multiple string parameters for each job. The parameters are common for all build jobs. I would like to set these parameters on global level so that I can be consumed across all stages. Along with stages I have a retry logic which tries for 2 times after first failure. Once it crosses 3 tries job bails.
At the moment I have configure parameters twice, first in initial build trigger and second in retry block. This is duplicate definition. Also at any time the parameters are same across all.
I tried to define parameters at top before stages begin, but these parameters are not used by the stages even though job defined in build step require the parameters.
pipeline {
agent {
label 'master'
}
parameters
{
string(name: 'VERSION', defaultValue: '', description: 'VERSION No.')
string(name: 'DEPLOY_TYPE', defaultValue: '', description: 'DEPLOY_TYPE')
string(name: 'TICKET', RELEASE: '$RELEASE', description: 'Release No.')
}
stage ("Stage1") {
steps {
script {
def retryAttempt = 0
try{
build(
job: 'Job1',
parameters: [
[
$class: 'StringParameterValue',
name: 'VERSION',
value: "${VERSION}"
],
[
$class: 'StringParameterValue',
name: 'DEPLOY_TYPE',
value: "${DEPLOY_TYPE}"
],
[
$class: 'StringParameterValue',
name: 'TICKET',
value: "${TICKET}"
]
]
)
}
catch(error) {
echo "First build failed, let's retry if accepted"
retry(2) {
build(
job: 'Job1',
parameters: [
[
$class: 'StringParameterValue',
name: 'VERSION',
value: "${VERSION}"
],
[
$class: 'StringParameterValue',
name: 'DEPLOY_TYPE',
value: "${DEPLOY_TYPE}"
],
[
$class: 'StringParameterValue',
name: 'TICKET',
value: "${TICKET}"
]
]
)
}
}
}
}
}
I want to use global parameters define once in pipeline and use all parameters across all stages.
def YOUR_VARIABLE pipeline { agent { label 'master' }....}
– milanbalazsdef my_var pipeline { agent any stages {....
Here is a very similar question: stackoverflow.com/questions/47716933/… – milanbalazs