Skip to content

Instantly share code, notes, and snippets.

@okram999
Last active April 12, 2019 05:08
Show Gist options
  • Save okram999/9af7e2c1e01de4900f33f583c4b2975a to your computer and use it in GitHub Desktop.
Save okram999/9af7e2c1e01de4900f33f583c4b2975a to your computer and use it in GitHub Desktop.
node('master') {
try{
//delete workspace
deleteDir()
/*
echo the parameters that are being passed to the job
*/
println "Validation of the metadata set as: $validate"
stage('tools') {
antHome = tool 'default-ant'
nodeHome = tool 'nodejs814'
jdk = tool name: 'JAVA1.8'
env.PATH="${env.PATH}:${nodeHome}/bin:${antHome}/bin"
env.JAVA_HOME = "${jdk}"
}
stage('CodeCheckout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [],
userRemoteConfigs: [[url: 'ssh://tfs.okram999.com:22/tfs/okram99901/SalesForce%20-%20okram%20organization/_git/okram_organization']]])
}
stage('Generate_Src&Package'){
sh '''node -v
npm list -g
git fetch --all
git branch -a
git checkout master
git checkout configChanges_config_R38.1
git diff --ignore-space-at-eol master configChanges_config_R38.1 | force-dev-tool changeset create devDeploy
mv src src_bk
mkdir src
mv config/deployments/devDeploy/* src/'''
}
stage('Validate') {
//validate = $validate
if("${validate}" == "true") {
sh 'ant -f build/build.xml deployEmptyCheckOnly -Dsfdc.serverurl=https://test.salesforce.com/ [email protected] -Dsfdc.password=okram999Password1~!'
} else {
println "Validation Skipped........"
}
}
stage('Deploy') {
ant = tool 'default-ant'
//redirect output to file and tail the file
log = sh (returnStdout: true, script: "ant -f build/build.xml deployCode -Dsfdc.serverurl=https://test.salesforce.com/ [email protected] -Dsfdc.password=okram999Password1~!").trim()
println "${log}"
//parse the String for the ID
def sub = { it.split("current deploy task: ")[1][0..15] } //Chnage this to the right one for deploy
def tag = sub(log)
println tag
stage('Archive') {
sh 'git add -A'
sh 'git commit -m "Pushing the deployed code from build $BUILD_NUMBER"'
sh "git tag v38.1-$tag"
sh "git push origin v38.1-${tag}"
}
stage('success_notify'){
emailext (
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<h1>Automated email noticfication from Jenkins CI system:</h1><p>The job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' was <strong>successfully</strong> executed. Deployed and archived SF deployment ID: '${tag}'<br />Attached is the build log.&nbsp;</p><p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
mimeType: 'text/html',
attachLog: true,
compressLog: true,
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider'], [$class: 'FailingTestSuspectsRecipientProvider'], [$class: 'FirstFailingBuildSuspectsRecipientProvider'], [$class: 'UpstreamComitterRecipientProvider']],
to: "[email protected]"
)
}
}
}
catch(err){
stage('failure_handler') {
echo "Caught: ${err}"
currentBuild.result = 'FAILURE'
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<h1>Automated email noticfication from Jenkins CI system:</h1><p>The job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' execution <strong>failed!!!</strong> <br />Attached is the build log.&nbsp;</p><p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
mimeType: 'text/html',
attachLog: true,
compressLog: true,
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider'], [$class: 'FailingTestSuspectsRecipientProvider'], [$class: 'FirstFailingBuildSuspectsRecipientProvider'], [$class: 'UpstreamComitterRecipientProvider']],
to: "[email protected]"
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment