Define dynamic stages with sequential steps.
This commit is contained in:
parent
c6cabe44eb
commit
fef59450af
|
@ -1,28 +0,0 @@
|
|||
def list
|
||||
pipeline {
|
||||
agent {
|
||||
label 'pipeline-agent'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Create Job List') {
|
||||
steps {
|
||||
script {
|
||||
// you may create your list here, lets say reading from a file after checkout
|
||||
list = ["Test-1", "Test-2", "Test-3", "Test-4", "Test-5"]
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Dynamic Stages') {
|
||||
steps {
|
||||
script {
|
||||
for(int i=0; i < list.size(); i++) {
|
||||
stage(list[i]){
|
||||
echo "Element: $i"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
def apps = "app1,app2,app3".split(",").findAll { it }.collect { it.trim() }
|
||||
def jobs = "job1,job2,job3,job4,job5".split(",").findAll { it }.collect { it.trim() }
|
||||
|
||||
def environment = env.ENVIRONMENT
|
||||
def version = env.VERSION
|
||||
def dynamicStages = [:]
|
||||
|
||||
if (apps.size() < 1) {
|
||||
error("ERROR: APPLICATIONS must be a comma-delimited list of applications to build")
|
||||
}
|
||||
|
||||
for (int i = 0; i < apps.size(); i++) {
|
||||
def app = apps[i]
|
||||
dynamicStages["stage-${app}"] = {
|
||||
node {
|
||||
stage("Build ${app}") {
|
||||
for (int i2 = 0; i2 < jobs.size(); i2++) {
|
||||
build "${i2}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Build apps(s)') {
|
||||
steps {
|
||||
script {
|
||||
parallel dynamicStages
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue