Created
August 3, 2020 15:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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