SHARE
TWEET

Untitled

a guest Jan 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env groovy
  2.  
  3. // This will extract the branch name based on Git Flow to be used
  4. //     for docker image tags and environment deployments
  5. String safeBranchName = 'develop'
  6. String openshiftCredential='****'
  7. String openshiftAppName='logviewer' // DO NOT CHANGE used for both docker repo and openshift application name 1:1
  8.  
  9. String dockerCredential='****'
  10. String dockerOrg='****'
  11. String jenkinsBuildEmailTo='****'
  12.  
  13. // *** DO NOT MODIFY ***
  14. String dockerPath="https://docker.****.com/$dockerOrg/$openshiftAppName:latest" // ORG AND REPO MUST EXIST
  15. // *** DO NOT MODIFY ***
  16.  
  17. // The Jenkins Global Pipeline Library that is being used is: https://github.****.com/jenkins-pipelines/global-pipeline-library
  18. @Library("com.****.jenkins.pipeline.library@master") _
  19.  
  20. pipeline {
  21.   agent {
  22.     label 'docker-maven-slave' // Jenkins build agent/slave, example: docker-oc-slave
  23.   }
  24. stages {
  25.     stage ('Create docker repository if not exists') {
  26.         steps {
  27.             glDockerRepoCreate dockerCredentialsId:"****",
  28.                     dockerHost:"docker.****.com",
  29.                     namespace:"****",
  30.                     repository:"****"
  31.         }
  32.     }
  33.   stage ('Build and Push Docker Image') {
  34.     steps {
  35.         script {
  36.             docker.withTool('docker-1.11.2') {
  37.                 docker.withRegistry('https://docker.****.com', "****") {
  38.                     newImage = docker.build("****/logviewer:$safeBranchName")
  39.                     newImage.push("latest")
  40.                 }
  41.             }
  42.         }
  43.     }
  44.   }
  45.  
  46. }
  47. post {
  48.     always {
  49.       echo 'This will always run'
  50.     }
  51.     success {
  52.       echo 'This will run only if successful'
  53.     }
  54.     failure {
  55.       echo 'This will run only if failed'
  56.       emailext body: "Build URL: ${BUILD_URL}",
  57.         subject: "$currentBuild.currentResult-$JOB_NAME",
  58.         to: "$jenkinsBuildEmailTo"
  59.     }
  60.     unstable {
  61.       echo 'This will run only if the run was marked as unstable'
  62.     }
  63.     changed {
  64.       echo 'This will run only if the state of the Pipeline has changed'
  65.       echo 'For example, if the Pipeline was previously failing but is now successful'
  66.     }
  67.   }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top