Created
February 17, 2020 09:39
-
-
Save levmichael3/7b25bbedd3980dd393e594107c48b24a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env groovy | |
pipeline { | |
options { | |
timestamps() | |
skipDefaultCheckout() | |
} | |
environment { | |
REPO_PATH = "***/***" | |
PROJECT = "***" | |
SELECT_BRANCH = "master" | |
BITBUCKET_SERVER = "https://*****" | |
REPOSITORY = "${env.BITBUCKET_SERVER}/${env.REPO_PATH}/${env.PROJECT}.git" | |
} | |
agent { | |
node { | |
label 'master' | |
} | |
} | |
stages { | |
stage ('Pull project'){ | |
steps { | |
pullProject("${env.SELECT_BRANCH}") | |
} | |
} | |
stage('DEBUG') { | |
steps { | |
script { | |
sh(returnStdout: true, script: "ls -alh").trim() | |
} | |
} | |
} | |
} | |
post { | |
changed { | |
script { | |
// Will trigger only when job status changes: GREEN -> RED, RED -> GREEN, etc | |
notifyStatusChangeViaEmail(currentBuild.currentResult) | |
} | |
} | |
always { | |
script { | |
// notifyStatusChangeViaEmail(currentBuild.currentResult) | |
cleanWs() | |
} | |
} | |
} | |
} | |
// *********************************************************************************************************************************************************************// | |
def pullProject(buildBranch){ | |
echo "Pulling from [${env.REPOSITORY}] Branch [${buildBranch}]" | |
checkout([$class: 'GitSCM', branches: [[name: "${buildBranch}"]], | |
doGenerateSubmoduleConfigurations: false, | |
extensions: [[$class: 'AuthorInChangelog'], [$class: 'CheckoutOption', timeout: 5]], | |
submoduleCfg: [], userRemoteConfigs: [[credentialsId: '*****', | |
url: "${env.REPOSITORY}"]]]) | |
} | |
def notifyStatusChangeViaEmail(buildStatus) { | |
def status | |
def extraMsg = "on branch [${env.SELECT_BRANCH}]" | |
def details = """<p>${buildStatus}: Pipeline ${env.JOB_NAME} ${extraMsg} [${env.BUILD_NUMBER}]:</p> | |
<p>Check console output at <a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a></p> | |
""" | |
switch (buildStatus) { | |
case 'SUCCESS': | |
status = 'is now green again!' | |
break | |
case 'UNSTABLE': | |
status = 'has become unstable..' | |
break | |
case 'FAILURE': | |
status = 'has turned RED :(' | |
break | |
} | |
emailext ( | |
subject: "${buildStatus}: Job '${env.JOB_NAME}' ${status}", | |
body: details, | |
to: '******' | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment