Skip to content

Instantly share code, notes, and snippets.

@timothyshort
Last active August 24, 2023 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save timothyshort/a1364b36a0ee1c0dca378e6f438c0e1c to your computer and use it in GitHub Desktop.
Save timothyshort/a1364b36a0ee1c0dca378e6f438c0e1c to your computer and use it in GitHub Desktop.
pipeline {
agent any
parameters {
string(name: 'server', defaultValue: "C:\\HexawareTraining\\Cohort1\\JenkinsLabs\\apache-tomcat-")
string(name: 'emailTo', defaultValue: "timothyjames.short@gmail.com")
}
triggers {
pollSCM('* * * * *')
}
tools {
maven 'jenkinsMaven'
}
stages {
stage('Build') {
steps {
bat """
cd freddie-app
mvn clean package
"""
}
}
stage('Deploy to Staging') {
steps {
echo 'Deploy to staging environment'
// Launch tomcat
bat """
cd ${params.server}qa\\bin
startup
"""
bat """
cd ${params.server}staging\\bin
startup
"""
// Code to move WAR to Tomcat
bat "xcopy /y freddie-app\\webapp\\target\\webapp.war ${params.server}qa\\webapps"
bat "xcopy /y freddie-app\\webapp\\target\\webapp.war ${params.server}staging\\webapps"
}
post {
success {
emailNotification('Successfully Deployed to Staging')
}
failure {
emailNotification('FAILED to deploy to staging')
}
}
}
}
}
def emailNotification(status) {
emailext(
to: "${params.emailTo}",
subject: "${status}",
body: "Job Name: <b>${env.JOB_NAME}</b> <br>" +
"Build: <b>${env.BUILD_NUMBER}</b> <br>" +
"<a href=${env.BUILD_URL}>Check Console Output</a>"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment