Skip to content

Instantly share code, notes, and snippets.

@mkutz
Created August 3, 2020 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkutz/a63c37b9af32a0052b894fcd8f6f0e41 to your computer and use it in GitHub Desktop.
Save mkutz/a63c37b9af32a0052b894fcd8f6f0e41 to your computer and use it in GitHub Desktop.
Jenkinsfile using parallel and when to pick one of multiple stages to be executed
#!/usr/bin/env groovy
// see https://jenkins.io/doc/book/pipeline/syntax/
pipeline {
agent any
parameters {
booleanParam(name: "RELEASE", defaultValue: false)
choice(name: "DEPLOY_TO", choices: ["", "INT", "PRE", "PROD"])
}
stages {
stage("Build") {
steps {
sh "./gradlew build"
}
}
stage("Publish") {
parallel {
stage('Pre-Release') {
when { expression { !params.RELEASE } }
steps {
sh "./gradlew preRelease"
}
}
stage("Release") {
when { expression { params.RELEASE } }
steps {
sh "./gradlew release"
}
}
}
}
stage("Deploy") {
parallel {
stage("INT") {
when { expression { params.DEPLOY_TO == "INT" } }
steps {
sh "./deploy int"
}
}
stage("PRE") {
when { expression { params.DEPLOY_TO == "PRE" } }
steps {
sh "./deploy.sh pre"
}
}
stage("PROD") {
when { expression { params.DEPLOY_TO == "PROD" } }
steps {
sh "./deploy.sh prod"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment