github.com/verrazzano/verrazzano@v1.7.1/release/builds/JenkinsfileForceCandidate (about) 1 // Copyright (c) 2022, 2023, 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 def SHORT_COMMIT_HASH 5 def VERRAZZANO_DEV_VERSION="" 6 def STARTED_BY_USER="" 7 8 pipeline { 9 options { 10 skipDefaultCheckout true 11 disableConcurrentBuilds() 12 timestamps () 13 } 14 15 agent { 16 docker { 17 image "${RELEASE_RUNNER_IMAGE}" 18 args "${RELEASE_RUNNER_DOCKER_ARGS}" 19 registryUrl "${RUNNER_DOCKER_REGISTRY_URL}" 20 registryCredentialsId 'ocir-pull-and-push-account' 21 label "internal" 22 } 23 } 24 25 parameters { 26 booleanParam (name: 'DRY_RUN', 27 description: 'Indicate whether this is a DRY run, which will do some stuff but will NOT force a new candidate', 28 defaultValue: true) 29 string (name: 'GIT_COMMIT_TO_FORCE_AS_CANDIDATE', 30 defaultValue: 'NONE', 31 description: 'This is the full git commit hash to FORCE to be the latest releasable candidate for the current release version on this branch.', 32 trim: true) 33 booleanParam (name: 'IGNORE_PRE_RELEASE_VALIDATION_FAILURES', 34 description: 'Ignore pre-release validation failures', 35 defaultValue: false) 36 } 37 38 environment { 39 OCI_OS_NAMESPACE = credentials('oci-os-namespace') 40 OCI_CLI_AUTH="api_key" 41 OCI_CLI_TENANCY = credentials('oci-tenancy') 42 OCI_CLI_USER = credentials('oci-user-ocid') 43 OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint') 44 OCI_CLI_KEY_FILE = credentials('oci-api-key') 45 OCI_OS_REGION = "us-phoenix-1" 46 OCI_REGION = "${env.OCI_OS_REGION}" 47 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 48 CLEAN_BRANCH_NAME = "${env.BRANCH_NAME.replace("/", "%2F")}" 49 FORCE_TYPE = "${params.DRY_RUN == true ? "DRY_RUN" : "FORCE_FOR_REAL"}" 50 } 51 52 stages { 53 stage('Verify Specified Commit can be Forced') { 54 steps { 55 script { 56 if (params.GIT_COMMIT_TO_FORCE_AS_CANDIDATE == "NONE") { 57 echo "Specific GIT commit was not specified, you must supply an explicit commit" 58 sh "exit 1" 59 } else { 60 scmCheckout() 61 } 62 echo "SCM checkout of ${env.GIT_BRANCH} at ${env.GIT_COMMIT}" 63 SHORT_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short=8 HEAD").trim() 64 echo "Short commit hash: $SHORT_COMMIT_HASH" 65 } 66 67 script { 68 dir ("${WORKSPACE}") { 69 def cleanBranchName = "${env.BRANCH_NAME.replace("/", "%2F")}" 70 sh """ 71 oci --region us-phoenix-1 os object get --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_BUCKET} --name ${cleanBranchName}/current-dev-version.txt --file ${WORKSPACE}/current_dev_version.txt 72 """ 73 def propsDevVersion = readProperties file: "current_dev_version.txt" 74 VERRAZZANO_DEV_VERSION = propsDevVersion['verrazzano-development-version'] 75 println("Current dev version is ${VERRAZZANO_DEV_VERSION}") 76 77 sh """ 78 # The existence of the versioned images.txt at the commit specific location in object storage is enough to confirm the commit and version. The update last periodics will also 79 # do this as well, but we are doing it here explicitly so that if the commit specified is not correct we can fail here in the initial stage 80 oci --region us-phoenix-1 os object head --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_COMMIT_BUCKET} --name ephemeral/${env.BRANCH_NAME}/${SHORT_COMMIT_HASH}/verrazzano_${VERRAZZANO_DEV_VERSION}-images.txt 81 """ 82 } 83 } 84 } 85 } 86 87 stage('Release Candidate Validation Checks') { 88 steps { 89 script { 90 releaseValidationChecks() 91 } 92 } 93 } 94 95 stage('Force Candidate') { 96 when { 97 expression { !params.DRY_RUN } 98 } 99 environment { 100 GIT_COMMIT_USED = "${env.GIT_COMMIT}" 101 } 102 steps { 103 script { 104 sh """ 105 # This will effectively use the commit specified as the last clean periodic test run. This will verify that all of the files required 106 # exist in object storage for that commit before copying things across. It will FAIL if that is not the case BEFORE any files are 107 # copied in, so if the commit doesn't have the necessary artifacts in Object Storage to do this it can't be used and won't leave us 108 # in a half baked state 109 ci/scripts/update_last_clean_periodic_test.sh ${VERRAZZANO_DEV_VERSION} ${SHORT_COMMIT_HASH} ${FORCE_TYPE} 110 """ 111 } 112 } 113 } 114 } 115 post { 116 always { 117 script { 118 if (notifyInSlack()) { 119 slackSend ( message: "User ${STARTED_BY_USER} started run to FORCE ${env.GIT_BRANCH} at ${env.GIT_COMMIT} to be treated as a passing periodic run to allow it to be seen as the last candidate. ${env.BUILD_URL}" ) 120 } 121 } 122 deleteDir() 123 } 124 } 125 } 126 127 def notifyInSlack() { 128 // Always notify if we are not doing a dry run 129 return !params.DRY_RUN 130 } 131 132 def getStartedByUser() { 133 def startedByUser = ""; 134 def causes = currentBuild.getBuildCauses() 135 echo "causes: " + causes.toString() 136 for (cause in causes) { 137 def causeString = cause.toString() 138 echo "current cause: " + causeString 139 def causeInfo = readJSON text: causeString 140 if (causeInfo.userId != null) { 141 startedByUser = causeInfo.userId 142 } 143 } 144 return startedByUser 145 } 146 147 def scmCheckout() { 148 echo "${NODE_LABELS}" 149 echo "SCM checkout of ${params.GIT_COMMIT_TO_FORCE_AS_CANDIDATE}" 150 def scmInfo = checkout([ 151 $class: 'GitSCM', 152 branches: [[name: params.GIT_COMMIT_TO_FORCE_AS_CANDIDATE]], 153 doGenerateSubmoduleConfigurations: false, 154 extensions: [], 155 submoduleCfg: [], 156 userRemoteConfigs: [[url: env.SCM_VERRAZZANO_GIT_URL]]]) 157 env.GIT_COMMIT = scmInfo.GIT_COMMIT 158 env.GIT_BRANCH = scmInfo.GIT_BRANCH 159 echo "SCM checkout of ${env.GIT_BRANCH} at ${env.GIT_COMMIT}" 160 // If the commit we were handed is not what the SCM says we are using, fail 161 if (!env.GIT_COMMIT.equals(params.GIT_COMMIT_TO_FORCE_AS_CANDIDATE)) { 162 error( "SCM didn't checkout the commit we expected. Expected: ${params.GIT_COMMIT_TO_FORCE_AS_CANDIDATE}, Found: ${scmInfo.GIT_COMMIT}") 163 } 164 } 165 166 def releaseValidationChecks() { 167 def built = build job: "verrazzano-prerelease-check/${CLEAN_BRANCH_NAME}", 168 parameters: [ 169 string (name: 'COMMIT_TO_USE', value: env.GIT_COMMIT), 170 booleanParam (name: 'IGNORE_PRE_RELEASE_VALIDATION_FAILURES', value: params.IGNORE_PRE_RELEASE_VALIDATION_FAILURES) 171 ], wait: true, propagate: false 172 println("Result of verrazzano-prerelease-check is ${built.result}") 173 dir ("${WORKSPACE}") { 174 copyArtifacts(projectName: "verrazzano-prerelease-check/${CLEAN_BRANCH_NAME}", 175 selector: specific("${built.number}")); 176 def releaseStatus = readFile file: "release_status.out" 177 currentBuild.displayName = "${currentBuild.displayName} : ${releaseStatus}" 178 } 179 }