Skip to content

Instantly share code, notes, and snippets.

@rantoniuk
Created August 27, 2019 12:10
Show Gist options
  • Save rantoniuk/4524baac466abf2a9b148af22bdfce3a to your computer and use it in GitHub Desktop.
Save rantoniuk/4524baac466abf2a9b148af22bdfce3a to your computer and use it in GitHub Desktop.
Jenkinsfile - deploying to environments depending on the choice param
// Requires:
// https://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin
pipeline {
agent {
label "master"
}
parameters {
choice(name: 'ENV', choices: ['DEV', 'TEST'], description: 'Select environment to deploy to')
gitParameter name: 'TAG', type: 'PT_BRANCH_TAG', sortMode: 'DESCENDING_SMART', defaultValue: 'develop'
}
environment {
CI = 'true'
TOMCAT_DEV = 'https://tomcat1/manager/text'
TOMCAT_TEST = 'https://tomcat2/manager/text'
}
options {
disableConcurrentBuilds()
timestamps()
}
stages {
stage('Build') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: "${params.TAG}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'bitbucket_svc', url: 'git@<account>.bitbucket.org:<account>/<repo>.git']]
])
sh 'mvn -B -DskipTests clean package'
}
} // end of build
stage('Deploy') {
steps {
script {
if (params.ENV == 'DEV'){
env.TOMCAT_URL = env.TOMCAT_DEV
}
if (params.ENV == 'TEST'){
env.TOMCAT_URL = env.TOMCAT_TEST
}
echo "Deploying TAG: $env.TAG to: $env.TOMCAT_URL"
}
deploy adapters: [tomcat8(credentialsId: 'tomcat-dev', path: '', url: "${TOMCAT_URL}" )], contextPath: '/', onFailure: false, war: 'target/ROOT.war'
}
} // end of deploy
} // end of stages
} // end of pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment