I have different apps in different projects. In dev project are together, but separate in the others. Like this:
dev project -> app1, app2
tst_intranet project -> app1
tst_internet project -> app2
Now my stages contains all the stages for both apps.
pipeline {
agent any
stages{
stage('Init which app is app1, and app2)
stage('Parameter initialization for app1')
stage('Deploy for app1')
stage('Parameter initialization for app2')
stage('Deploy for app2')
}
}
But, I want to to run all stages, when I deploy for dev, but if I deploy for tst_intranet project, I want to run only "for app1" stages, or "for app2" stages, when I deploy for tst_internet.
Thanks for your helping.
CodePudding user response:
As Vasiliy Ratanov mentioned you can use when directive to conditionally run your stages. In your case something like below.
pipeline {
agent any
stages{
stage('Init which app is app1, and app2)
stage('Parameter initialization for app1') {
when { expression { environment == "dev" || environment == "tst_intranet" } }
steps{}
}
stage('Deploy for app1') {
when { expression { environment == "dev" || environment == "tst_intranet" } }
steps{}
}
stage('Parameter initialization for app2') {
when { expression { environment == "dev" || environment == "tst_internet" } }
steps{}
}
stage('Deploy for app2') {
when { expression { environment == "dev" || environment == "tst_internet" } }
steps{}
}
}
}
CodePudding user response:
Thanks for your help, its working.