Add some useful and tested examples of dynamic pipelines.

This commit is contained in:
Manuele Simi 2019-08-16 23:24:48 -04:00
parent 4ec0d9f47b
commit c6cabe44eb
3 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,33 @@
def apps = "job1,job2,job3,job4"
def applications = apps.split(",").findAll { it }.collect { it.trim() }
def environment = env.ENVIRONMENT
def version = env.VERSION
def jobs = [:]
if (applications.size() < 1) {
error("ERROR: APPLICATIONS must be a comma-delimited list of applications to build")
}
for (int i = 0; i < applications.size(); i++) {
def app = applications[i]
jobs["jobs-${app}"] = {
node {
stage("Build ${app}") {
build "${app}"
}
}
}
}
pipeline {
agent none
stages {
stage('Build apps(s)') {
steps {
script {
parallel jobs
}
}
}
}
}

View File

@ -0,0 +1,28 @@
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"
}
}
}
}
}
}
}

51
examples/parallel_nested Normal file
View File

@ -0,0 +1,51 @@
pipeline {
agent any
stages {
stage('Non-Parallel Stage') {
steps {
echo 'This stage will be executed first.'
}
}
stage('Parallel Stage') {
when {
branch 'master'
}
failFast true
parallel {
stage('Branch A') {
agent {
label "for-branch-a"
}
steps {
echo "On Branch A"
}
}
stage('Branch B') {
agent {
label "for-branch-b"
}
steps {
echo "On Branch B"
}
}
stage('Branch C') {
agent {
label "for-branch-c"
}
stages {
stage('Nested 1') {
steps {
echo "In stage Nested 1 within Branch C"
}
}
stage('Nested 2') {
steps {
echo "In stage Nested 2 within Branch C"
}
}
}
}
}
}
}
}