Quantcast
Channel: DevOps tips & tricks
Viewing all articles
Browse latest Browse all 181

Call another job in Jenkins declarative pipeline with parameters

$
0
0

 HOWTO

 

Parameters on the pipeline job

pipeline {
agent any
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')

text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')

booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')

choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')

password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
}
stages {
stage('Example') {
steps {
echo "Hello ${params.PERSON}"

echo "Biography: ${params.BIOGRAPHY}"

echo "Toggle: ${params.TOGGLE}"

echo "Choice: ${params.CHOICE}"

echo "Password: ${params.PASSWORD}"
}
}
}
}

 

Called job


pipeline {
agent {
label 'dave_node'
}
parameters {
string(name: 'branch', defaultValue: 'main', description: 'Some branch')
}
stages {
stage('CalledJob') {

steps {

echo "Build CalledJob branch ${params.branch}"

script {
params.each {param ->
println "${param.key} -> ${param.value} "
} }


git url: 'https://github.com/dveselka/calledjob/', credentialsId: 'daveCredentials', branch: "${params.branch}"
}
}
}
}


Calling job


stage('BuildOtherJob') {
steps {

echo "Call other job job"
script {
build job: 'jobtocall', parameters: [
string(name: 'branch', value: "some_branch")
]
}
}
}



Viewing all articles
Browse latest Browse all 181

Trending Articles