Skip to content

Instantly share code, notes, and snippets.

@mkutz
Created August 3, 2020 15:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkutz/6d057502d5c126ddf8f515ca52a96bed to your computer and use it in GitHub Desktop.
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
#!/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