Answer the question
In order to leave comments, you need to log in
How to change stage name dynamically in Jenkins declarative pipeline?
We decided to try to move away from the Scripted Pipeline towards the Declarative Pipeline
and faced the question of how to dynamically redefine the name of the stage?
def template1 = "spread_sshkeys"
pipeline {
agent any
stages {
stage ("Checkout") {
steps {
deleteDir()
checkout scm
sh "git submodule foreach --recursive git pull origin master"
}
}
stage('test') {
steps {
script {
sh "ls -las; cd jenkins-ci-examples; ls -las";
}
}
}
stage('run template ${template1}') {
steps {
sh "ls -las; cd jenkins-ci-examples; ls -las";
}
}
}
}
stage('run template ${template1}')
Answer the question
In order to leave comments, you need to log in
the answer to the question is here
https://stackoverflow.com/questions/68136020/how-m...
in short, you need to write something like this
def template1 ="spread_sshkeys"
pipeline {
agent any
stages {
stage('Dynamic Stages') {
steps {
script {
stage("import template ${template1}"){
println("${env.STAGE_NAME}")
}
stage("run template ${template1}"){
println("${env.STAGE_NAME}")
}
}
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question