How to loop parametrized parallel stages in Jenkins declarative pipeline? (Or scripted pipeline, if declarative is not able to)
Here is my simple pseudo example. How to loop ('deploy serverN') stages?
Array may have 1..n variables.
I would not like to duplicate code. There must be a way in Jenkins pipelines?? Or should I use matrix. I have tried a few, but not succesfully.
@Library('adm-jenkins-lib@trunk')
def SERVERS = ['server1.com','server2.com',...]
deployPipeline([servers: SERVERS, manage_tasks: TASKS])
...
def call(Map params) {
pipeline {
agent any
environment {
}
stages {
stage ('common task') {
}
stage ('Deploying..') {
parallel {
stage ('deploy server1') {
stages {
stage ('deploy tasks #1') {
steps { ... }
}
stage ('deploy tasks #2') {
steps { ... }
}
}
stage ('deploy server2') {
stages {
stage ('deploy tasks #1') {
steps { ... }
}
stage ('deploy tasks #2') {
steps { ... }
}
}
}
}
}
}
}
}
I have tried also this kind of approach but it is not working perfect because previous stages are not dependent on next ones.
stage ('deploy serverX') {
when { expression { params.manage_tasks =~ /task01/ } }
steps {
script {
servers = params.servers
servers.each { server ->
deploys[server] = {
sh "run task#1 stuff.."
}
}
parallel deploys
}
}
}
It should look like this in Blue Ocean (but dynamically created) : It should look like this in Blue Ocean