Last active
August 24, 2023 16:19
-
-
Save timothyshort/a1364b36a0ee1c0dca378e6f438c0e1c to your computer and use it in GitHub Desktop.
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
pipeline { | |
agent any | |
parameters { | |
string(name: 'server', defaultValue: "C:\\HexawareTraining\\Cohort1\\JenkinsLabs\\apache-tomcat-") | |
string(name: 'emailTo', defaultValue: "[email protected]") | |
} | |
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