Created
February 7, 2019 10:43
-
-
Save syakuis/db1fcb5e38d0d42cdb6fa790bcbc900a to your computer and use it in GitHub Desktop.
jenkins pipeline groovy script (with telegram)
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
def failureReport = { text -> "\r\n------------ Finish Report ------------\r\n${text}------------ Finish Report Report ------------\r\n" } | |
def botUrl = "https://api.telegram.org/bot${env.BOT_TOKEN}/sendMessage" | |
def bot = { text -> sh "curl -s -X POST ${botUrl} -d chat_id=${env.BOT_CHAT_ID} -d text='#${env.BUILD_ID} ${text}'" } | |
node { | |
bot("build starting") | |
def mvnHome | |
stage('Preparation') { | |
if (env.USE_GIT_PULL == "true") { | |
git branch: env.GIT_BRANCH, credentialsId: 'gitlab', url: env.GIT_URL | |
} | |
mvnHome = tool 'maven' | |
} | |
stage('Build') { | |
if (env.USE_BUILD == "true") { | |
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore -DtargetName=local-web clean install" | |
} | |
} | |
stage('Deploy') { | |
def sites = readJSON file: "deploy-sites.json" | |
def report = "" | |
for (item in sites) { | |
def info = "${item.name} = ${item.host}:${item.port}" | |
if (item.enable) { | |
try { | |
println("deploy starting ==> ${info}") | |
sh "curl -v -u ${env.USERNAME}:${env.PASSWORD} 'http://${item.host}:${item.port}/manager/text/undeploy?path=/&update=true'" | |
sh "curl -v -u ${env.USERNAME}:${env.PASSWORD} -T target/local-web.war 'http://${item.host}:${item.port}/manager/text/deploy?path=/&update=true'" | |
} catch(ex) { | |
println("deploy failure ==> ${info}") | |
//throw ex | |
println(ex) | |
report = report + "failure >>> ${info}\r\n" | |
} | |
} else { | |
println("deploy ignore ==> ${info}") | |
report = report + "ignore >>> ${info}\r\n" | |
} | |
} | |
if (report != "") { | |
report = failureReport(report) | |
println report | |
} | |
bot("build finish${report}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment