github.com/verrazzano/verrazzano@v1.7.0/release/builds/JenkinsfilePreRelease (about) 1 // Copyright (c) 2021, 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 DOCKER_IMAGE_TAG 5 def releaseBuild 6 def RELEASE_JOB_NAME 7 def RELEASE_BRANCH_COMMIT 8 def IS_PATCH_RELEASE = false 9 def VERRAZZANO_DEV_VERSION 10 11 pipeline { 12 options { 13 skipDefaultCheckout true 14 copyArtifactPermission('*'); 15 timestamps () 16 } 17 18 agent { 19 docker { 20 image "${RELEASE_RUNNER_IMAGE}" 21 args "${RELEASE_RUNNER_DOCKER_ARGS}" 22 registryUrl "${RUNNER_DOCKER_REGISTRY_URL}" 23 registryCredentialsId 'ocir-pull-and-push-account' 24 label "internal" 25 } 26 } 27 28 parameters { 29 string (description: 'The source commit for the release (required for full release)', name: 'COMMIT_TO_USE', defaultValue: 'NONE', trim: true ) 30 booleanParam (description: 'Create a release candidate EVEN if pre-release validations fail', name: 'IGNORE_PRE_RELEASE_VALIDATION_FAILURES', defaultValue: false) 31 string (name: 'VERRAZZANO_HELPER_BRANCH', 32 defaultValue: 'master', 33 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', 34 trim: true) 35 } 36 37 environment { 38 OCR_CREDS = credentials('ocr-pull-and-push-account') 39 NETRC_FILE = credentials('netrc') 40 DOCKER_CREDS = credentials('github-packages-credentials-rw') 41 DOCKER_REPO = 'ghcr.io' 42 GITHUB_CREDENTIALS = credentials('github_rw') 43 CLEAN_BRANCH_NAME = "${env.BRANCH_NAME.replace("/", "%2F")}" 44 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 45 PERIODIC_JOB_PROJECT_NAME = 'verrazzano-periodic-triggered-tests' 46 OBJECT_STORAGE_NS = credentials('oci-os-namespace') 47 OCI_OS_NAMESPACE = credentials('oci-os-namespace') 48 OCI_CLI_AUTH="api_key" 49 OCI_CLI_TENANCY = credentials('oci-tenancy') 50 OCI_CLI_USER = credentials('oci-user-ocid') 51 OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint') 52 OCI_CLI_KEY_FILE = credentials('oci-api-key') 53 OCI_CLI_REGION = "us-phoenix-1" 54 OCI_REGION = "${env.OCI_CLI_REGION}" 55 OCI_OS_SHARED_BUCKET="build-shared-files" 56 } 57 58 stages { 59 stage('Clean workspace and checkout') { 60 steps { 61 sh """ 62 echo "${NODE_LABELS}" 63 """ 64 script { 65 if (params.COMMIT_TO_USE == "NONE") { 66 echo "Specific GIT commit was not specified, use current head" 67 def scmInfo = checkout scm 68 env.GIT_COMMIT = scmInfo.GIT_COMMIT 69 env.GIT_BRANCH = scmInfo.GIT_BRANCH 70 } else { 71 echo "SCM checkout of ${params.COMMIT_TO_USE}" 72 def scmInfo = checkout([ 73 $class: 'GitSCM', 74 branches: [[name: params.COMMIT_TO_USE]], 75 doGenerateSubmoduleConfigurations: false, 76 extensions: [], 77 submoduleCfg: [], 78 userRemoteConfigs: [[url: env.SCM_VERRAZZANO_GIT_URL]]]) 79 env.GIT_COMMIT = scmInfo.GIT_COMMIT 80 env.GIT_BRANCH = scmInfo.GIT_BRANCH 81 // If the commit we were handed is not what the SCM says we are using, fail 82 if (!env.GIT_COMMIT.equals(params.COMMIT_TO_USE)) { 83 echo "SCM didn't checkout the commit we expected. Expected: ${params.COMMIT_TO_USE}, Found: ${env.GIT_COMMIT}" 84 sh "exit 1" 85 } 86 } 87 // setup credential retrieval for possible release branch push 88 sh """ 89 git config credential.https://github.com.username ${GITHUB_CREDENTIALS_USR} 90 git config credential.helper '/bin/bash ${WORKSPACE}/release/scripts/credential_helper.sh' 91 """ 92 echo "SCM checkout of ${env.GIT_BRANCH} at ${env.GIT_COMMIT}" 93 RELEASE_BRANCH_COMMIT = env.GIT_COMMIT 94 } 95 96 script { 97 def props = readProperties file: '.verrazzano-development-version' 98 VERRAZZANO_DEV_VERSION = props['verrazzano-development-version'] 99 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 100 SHORT_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short=8 HEAD").trim() 101 // update the description with some meaningful info 102 currentBuild.description = SHORT_COMMIT_HASH + " : " + env.GIT_COMMIT + " : " + params.COMMIT_TO_USE 103 } 104 script { 105 sh """ 106 echo "Downloading verrazzano-helper from object storage" 107 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 108 chmod uog+x ${WORKSPACE}/verrazzano-helper 109 """ 110 } 111 } 112 } 113 114 stage('Release Candidate Validation Checks') { 115 environment { 116 IGNORE_FAILURES = "false" 117 TICKET_SERVICE_USERNAME = credentials('ticket-service-username') 118 TICKET_SERVICE_PASSWORD = credentials('ticket-service-password') 119 OCI_OS_BUCKET="verrazzano-builds" 120 OCI_OS_COMMIT_BUCKET="verrazzano-builds-by-commit" 121 OCI_CLI_AUTH="api_key" 122 OCI_CLI_TENANCY = credentials('oci-tenancy') 123 OCI_CLI_USER = credentials('oci-user-ocid') 124 OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint') 125 OCI_CLI_KEY_FILE = credentials('oci-api-key') 126 OCI_CLI_REGION = "us-phoenix-1" 127 OCI_REGION = "${env.OCI_CLI_REGION}" 128 RELEASE_VERSION = "${params.RELEASE_VERSION}" 129 VERRAZZANO_RELEASE_PREFIX = "verrazzano-${VERRAZZANO_DEV_VERSION}" 130 VERRAZZANO_LITE_BUNDLE = "${VERRAZZANO_RELEASE_PREFIX}-lite.zip" 131 VERRAZZANO_FULL_BUNDLE = "${VERRAZZANO_RELEASE_PREFIX}.zip" 132 VZ_LITE = "vz-lite" 133 VZ_FULL = "vz-full" 134 } 135 steps { 136 script { 137 sh """ 138 cd ${WORKSPACE} 139 echo "Ensuring release artifacts exist for the specified commit id." 140 echo "The commit here should correspond to the commit id from a successful periodic test run which produced artifacts which can be released" 141 ./release/scripts/get_release_artifacts.sh ${env.BRANCH_NAME} ${SHORT_COMMIT_HASH} ${VERRAZZANO_FULL_BUNDLE} ${VZ_FULL} "VERIFY-ONLY" 142 ./release/scripts/get_release_artifacts.sh ${env.BRANCH_NAME} ${SHORT_COMMIT_HASH} ${VERRAZZANO_LITE_BUNDLE} ${VZ_LITE} "VERIFY-ONLY" 143 """ 144 145 sh """ 146 set +e 147 cd ${WORKSPACE} 148 echo "Performing pre-release validation checks for target version ${VERRAZZANO_DEV_VERSION}, ignore failures is ${params.IGNORE_PRE_RELEASE_VALIDATION_FAILURES}" 149 export IGNORE_FAILURES=${params.IGNORE_PRE_RELEASE_VALIDATION_FAILURES} 150 ./release/scripts/prerelease_validation.sh $VERRAZZANO_DEV_VERSION > $WORKSPACE/prerelease_validation.out 151 if [ \$? -eq 0 ]; then 152 echo "Passed pre-release checks for ${VERRAZZANO_DEV_VERSION}, promoting this to the latest releasable candidate" 153 echo "git-commit=${env.GIT_COMMIT}" > $WORKSPACE/last-${VERRAZZANO_DEV_VERSION}-releasable-candidate-commit.txt 154 oci --region us-phoenix-1 os object put --force --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_BUCKET} --name ${CLEAN_BRANCH_NAME}/last-$VERRAZZANO_DEV_VERSION-releasable-candidate-commit.txt --file $WORKSPACE/last-${VERRAZZANO_DEV_VERSION}-releasable-candidate-commit.txt 155 echo "RELEASE CANDIDATE" > release_status.out 156 else 157 echo "Failed pre-release checks for ${VERRAZZANO_DEV_VERSION}" 158 echo "NOT RELEASABLE" > release_status.out 159 fi 160 oci --region us-phoenix-1 os object put --force --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_BUCKET} --name ${CLEAN_BRANCH_NAME}/current-dev-version.txt --file $WORKSPACE/.verrazzano-development-version 161 set -e 162 """ 163 def releaseStatus = readFile file: "release_status.out" 164 currentBuild.displayName = "${currentBuild.displayName} : ${releaseStatus}" 165 if (currentBuild.displayName.contains("NOT RELEASABLE")) { 166 currentBuild.result = "FAILED" 167 } 168 } 169 } 170 } 171 } 172 post { 173 always { 174 script { 175 writeUpstreamBuildInfo(currentBuild) 176 sh "echo ${env.GIT_COMMIT} > ${WORKSPACE}/git_commit.out" 177 } 178 archiveArtifacts artifacts: '**/prerelease_validation.out,**/release_status.out,**/upstream_periodic_test_build_number.out,**/git_commit.out', allowEmptyArchive: true 179 } 180 } 181 } 182 183 def writeUpstreamBuildInfo(currBuild) { 184 println("upstream builds: ${currBuild.upstreamBuilds}") 185 currBuild.upstreamBuilds.each { 186 println("upstream project name: ${it.projectName}"); 187 println("upstream build full project name: ${it.fullProjectName} , comparing to ${env.PERIODIC_JOB_PROJECT_NAME}/${CLEAN_BRANCH_NAME}, are they equal: " + 188 it.fullProjectName.equals("${env.PERIODIC_JOB_PROJECT_NAME}/${CLEAN_BRANCH_NAME}") + " are they equal 2? " + 189 (it.fullProjectName == "${env.PERIODIC_JOB_PROJECT_NAME}/${CLEAN_BRANCH_NAME}")) 190 println("upstream build number: ${it.number}") 191 } 192 upstreamPeriodicBuild = currBuild.upstreamBuilds.find { it.fullProjectName == "${env.PERIODIC_JOB_PROJECT_NAME}/${CLEAN_BRANCH_NAME}" } 193 println("found upstream periodic build ${upstreamPeriodicBuild}") 194 if (upstreamPeriodicBuild != null) { 195 sh "echo ${upstreamPeriodicBuild.number} > ${WORKSPACE}/upstream_periodic_test_build_number.out" 196 } 197 }