Created
August 3, 2020 15:24
-
-
Save mkutz/6d057502d5c126ddf8f515ca52a96bed to your computer and use it in GitHub Desktop.
Jenkinsfile using script and switch/case to pick one of multiple steps to be executed
This file contains hidden or 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") { | |
steps { | |
script { | |
switch(params.DEPLOY_TO) { | |
case "INT": echo "./deploy.sh int"; break | |
case "PRE": echo "./deploy.sh pre"; break | |
case "PROD": echo "./deploy.sh prod"; break | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment