github.com/verrazzano/verrazzano@v1.7.0/ci/ticket-commits/JenkinsfileCommits (about) 1 // Copyright (c) 2021, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 pipeline { 5 options { 6 timestamps () 7 skipDefaultCheckout true 8 } 9 10 agent { 11 docker { 12 image "${RUNNER_DOCKER_IMAGE}" 13 args "${RUNNER_DOCKER_ARGS}" 14 registryUrl "${RUNNER_DOCKER_REGISTRY_URL}" 15 registryCredentialsId 'ocir-pull-and-push-account' 16 label "internal" 17 } 18 } 19 20 parameters { 21 string (name: 'GIT_COMMIT_TO_USE', 22 defaultValue: '', 23 description: 'Record all ticket commits after (and including) this commit hash (defaults to using Jenkins change set)', 24 trim: true) 25 string (name: 'VERRAZZANO_HELPER_BRANCH', 26 defaultValue: 'master', 27 description: 'verrazzano-helper branch. master is used for 1.3+, release-1.2 is used for 1.2 and earlier, user branch name is used when testing verrazzano-helper changes', 28 trim: true) 29 } 30 environment { 31 OCI_CLI_AUTH="api_key" 32 OCI_CLI_TENANCY = credentials('oci-tenancy') 33 OCI_CLI_USER = credentials('oci-user-ocid') 34 OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint') 35 OCI_CLI_KEY_FILE = credentials('oci-api-key') 36 OCI_CLI_REGION = "us-phoenix-1" 37 OCI_REGION = "${env.OCI_CLI_REGION}" 38 OCI_OS_NAMESPACE = credentials('oci-os-namespace') 39 OCI_OS_SHARED_BUCKET="build-shared-files" 40 } 41 42 stages { 43 stage('Clean workspace and checkout') { 44 environment { 45 GOPATH = '/home/opc/go' 46 GO_REPO_PATH = "${GOPATH}/src/github.com/verrazzano" 47 NETRC_FILE = credentials('netrc') 48 } 49 steps { 50 script { 51 def scmInfo = checkout([ 52 $class: 'GitSCM', 53 branches: [[name: env.BRANCH_NAME]], 54 extensions: [[$class: 'LocalBranch']], 55 userRemoteConfigs: [[refspec: '+refs/heads/*:refs/remotes/origin/*', url: env.SCM_VERRAZZANO_GIT_URL]]]) 56 57 sh """ 58 echo "${NODE_LABELS}" 59 echo "SCM checkout of ${scmInfo.GIT_BRANCH} at ${scmInfo.GIT_COMMIT}" 60 61 cp -f "${NETRC_FILE}" $HOME/.netrc 62 chmod 600 $HOME/.netrc 63 64 rm -rf ${GO_REPO_PATH}/verrazzano 65 mkdir -p ${GO_REPO_PATH}/verrazzano 66 tar cf - . | (cd ${GO_REPO_PATH}/verrazzano/ ; tar xf -) 67 """ 68 } 69 script { 70 sh """ 71 echo "Downloading verrazzano-helper from object storage" 72 oci --region us-phoenix-1 os object get --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_SHARED_BUCKET} --name ${params.VERRAZZANO_HELPER_BRANCH}/verrazzano-helper --file ${WORKSPACE}/verrazzano-helper 73 chmod uog+x ${WORKSPACE}/verrazzano-helper 74 """ 75 } 76 } 77 } 78 79 stage('Update tracking tickets with commits') { 80 environment { 81 TICKET_SERVICE_USERNAME = credentials('ticket-service-username') 82 TICKET_SERVICE_PASSWORD = credentials('ticket-service-password') 83 } 84 steps { 85 script { 86 def tmpfile=sh(returnStdout: true, script: "mktemp").trim() 87 88 // get the commits from the change set 89 def commitList = getCommitList() 90 91 sh """ 92 # if the commit hash is specified in the build params, get that commit and all commits after it 93 if [ -n "${params.GIT_COMMIT_TO_USE}" ]; then 94 git log --pretty=format:%H ${params.GIT_COMMIT_TO_USE}^.. > ${tmpfile} 95 else 96 printf "${commitList}" > ${tmpfile} 97 fi 98 99 echo Processing commits: 100 cat ${tmpfile}; echo 101 102 ${WORKSPACE}/verrazzano-helper update ticket-commits --commit-file "${tmpfile}" --backport-labels --token unused --ticket-env=prod 103 """ 104 } 105 } 106 } 107 } 108 109 post { 110 failure { 111 script { 112 if (env.GIT_BRANCH == "master" || env.GIT_BRANCH ==~ "release-*" ) { 113 pagerduty(resolve: false, serviceKey: "$SERVICE_KEY", incDescription: "Verrazzano: ${env.JOB_NAME} - Failed", incDetails: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}") 114 slackSend ( channel: "$SLACK_ALERT_CHANNEL", message: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n\nBlue Ocean:\n${env.RUN_DISPLAY_URL}\n\n" ) 115 } 116 } 117 } 118 cleanup { 119 deleteDir() 120 } 121 } 122 } 123 124 // Fetches git commits from the change set and returns a string of the commit ids 125 // separated with newlines. 126 @NonCPS 127 def getCommitList() { 128 echo "Checking for change sets" 129 def commitList = "" 130 def changeSets = currentBuild.changeSets 131 for (int i = 0; i < changeSets.size(); i++) { 132 echo "Get commits from change set" 133 def commits = changeSets[i].items 134 for (int j = 0; j < commits.length; j++) { 135 def commit = commits[j] 136 def id = commit.commitId 137 commitList = commitList + "\n" + id 138 } 139 } 140 return commitList 141 }