github.com/verrazzano/verrazzano@v1.7.0/release/builds/JenkinsfileSourceArchive (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 pipeline { 5 options { 6 skipDefaultCheckout true 7 timestamps () 8 } 9 10 agent { 11 docker { 12 image "${RELEASE_RUNNER_IMAGE}" 13 args "${RELEASE_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 (description: 'The release branch', name: 'RELEASE_BRANCH', defaultValue: 'NONE', trim: true) 22 string (description: 'The full git commit hash of the Verrazzano source to get the scripts used by the automation', name: 'COMMIT_TO_USE', defaultValue: 'NONE', trim: true ) 23 string (description: 'The release version (major.minor.patch format, e.g. 1.5.0) used to name the source archive', name: 'RELEASE_VERSION', defaultValue: 'NONE', trim: true) 24 string (description: 'verrazzano-helper branch, use the appropriate release branch', name: 'VERRAZZANO_HELPER_BRANCH', 25 defaultValue: 'master', trim: true) 26 } 27 28 environment { 29 OBJECT_STORAGE_NS = credentials('oci-os-namespace') 30 OBJECT_STORAGE_BUCKET="verrazzano-builds" 31 OCI_OS_COMMIT_BUCKET="verrazzano-builds-by-commit" 32 OCI_OS_SHARED_BUCKET="build-shared-files" 33 OCI_REGION="us-phoenix-1" 34 OCI_CLI_AUTH="api_key" 35 OCI_CLI_TENANCY = credentials('oci-tenancy') 36 OCI_CLI_USER = credentials('oci-user-ocid') 37 OCI_CLI_FINGERPRINT = credentials('oci-api-key-fingerprint') 38 OCI_CLI_KEY_FILE = credentials('oci-api-key') 39 40 RELEASE_VERSION = "${params.RELEASE_VERSION}" 41 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 42 43 REPO_URLS = "source_repo_urls.properties" 44 PUBLIC_REPO_URLS = "public_source_repo_urls.properties" 45 INTERNAL_REPO_URLS = "internal_source_repo_urls.properties" 46 47 // Keycloak had a dependency on keycloak-containers repo earlier, which is not the case now. 48 // Although there are no additional repositories for now, keeping it to support any changes in future. 49 ADDITIONAL_REPO_URLS = "source_repo_additional.properties" 50 51 // Variable to hold the standard output and error from the script downloading the source 52 DOWNLOAD_SOURCE_OUT = "download_source.out" 53 54 // Variable to hold the standard output and error from the script archiving the downloaded source 55 ARCHIVE_SOURCE_OUT = "archive_source.out" 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 echo "SCM checkout of ${env.GIT_BRANCH} at ${env.GIT_COMMIT}" 88 } 89 90 script { 91 def props = readProperties file: '.verrazzano-development-version' 92 VERRAZZANO_DEV_VERSION = props['verrazzano-development-version'] 93 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 94 SHORT_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short=8 HEAD").trim() 95 // update the description with some meaningful info 96 currentBuild.description = SHORT_COMMIT_HASH + " : " + env.GIT_COMMIT + " : " + params.COMMIT_TO_USE 97 } 98 99 } 100 } 101 102 stage('Download Repo URLs') { 103 environment { 104 GITHUB_AUTH_TOKEN = credentials('github-api-token-release-process') 105 } 106 steps { 107 script { 108 sh """ 109 oci --region ${OCI_REGION} os object get --namespace ${OBJECT_STORAGE_NS} -bn ${OCI_OS_SHARED_BUCKET} --name ${params.VERRAZZANO_HELPER_BRANCH}/verrazzano-helper --file ${WORKSPACE}/verrazzano-helper 110 chmod uog+x ${WORKSPACE}/verrazzano-helper 111 112 # Redirect the output of verrazzano-helper get repo-urls to files 113 ${WORKSPACE}/verrazzano-helper get repo-urls all > ${WORKSPACE}/${REPO_URLS} 114 ${WORKSPACE}/verrazzano-helper get repo-urls public_repos > ${WORKSPACE}/${PUBLIC_REPO_URLS} 115 ${WORKSPACE}/verrazzano-helper get repo-urls internal_repos > ${WORKSPACE}/${INTERNAL_REPO_URLS} 116 ${WORKSPACE}/verrazzano-helper get repo-urls additional_repos > ${WORKSPACE}/${ADDITIONAL_REPO_URLS} 117 """ 118 } 119 } 120 } 121 122 stage('Download Image List') { 123 steps { 124 script { 125 sh """ 126 cd ${WORKSPACE} 127 oci --region ${OCI_REGION} os object get --namespace ${OBJECT_STORAGE_NS} -bn ${OBJECT_STORAGE_BUCKET} --name ${params.RELEASE_BRANCH}/verrazzano_${VERRAZZANO_DEV_VERSION}-images.txt --file ${WORKSPACE}/verrazzano_${VERRAZZANO_DEV_VERSION}-images.txt 128 """ 129 } 130 } 131 } 132 133 stage('Validate Repo URLs') { 134 steps { 135 script { 136 sh """ 137 # Dry run to ensure REPO_URLS contains the URLs for all the images listed in verrazzano-images.txt 138 ${WORKSPACE}/release/scripts/download_source_prt.sh -i ${WORKSPACE}/verrazzano_${VERRAZZANO_DEV_VERSION}-images.txt -r ${WORKSPACE}/${REPO_URLS} -s ${WORKSPACE}/downloaded_source -d true 139 """ 140 } 141 } 142 } 143 144 stage('Download Source') { 145 steps { 146 script { 147 withCredentials([gitUsernamePassword(credentialsId: 'gitlab_rw', gitToolName: 'git-tool')]) { 148 sh """ 149 ${WORKSPACE}/release/scripts/download_source_prt.sh -i ${WORKSPACE}/verrazzano_${VERRAZZANO_DEV_VERSION}-images.txt -r ${WORKSPACE}/${INTERNAL_REPO_URLS} -s ${WORKSPACE}/downloaded_source -c true >> ${DOWNLOAD_SOURCE_OUT} 2>&1 150 ${WORKSPACE}/release/scripts/download_source_prt.sh -a ${WORKSPACE}/${ADDITIONAL_REPO_URLS} -s ${WORKSPACE}/downloaded_source >> ${DOWNLOAD_SOURCE_OUT} 2>&1 151 """ 152 } 153 154 withCredentials([gitUsernamePassword(credentialsId: 'github_rw', gitToolName: 'git-tool')]) { 155 sh """ 156 ${WORKSPACE}/release/scripts/download_source_prt.sh -i ${WORKSPACE}/verrazzano_${VERRAZZANO_DEV_VERSION}-images.txt -r ${WORKSPACE}/${REPO_URLS} -s ${WORKSPACE}/downloaded_source >> ${DOWNLOAD_SOURCE_OUT} 2>&1 157 """ 158 } 159 } 160 } 161 } 162 stage('Create Source Archive') { 163 steps { 164 script { 165 sh """ 166 mkdir -p ${WORKSPACE}/archive_dir 167 ${WORKSPACE}/release/scripts/archive_source_prt.sh ${WORKSPACE}/downloaded_source ${WORKSPACE}/archive_dir ${params.RELEASE_VERSION} >> ${ARCHIVE_SOURCE_OUT} 2>&1 168 """ 169 } 170 } 171 } 172 } 173 post { 174 always { 175 sh """ 176 echo "Sorting the source repository URLs before archiving" 177 if [ -f ${REPO_URLS} ]; 178 then 179 sort -u -o ${REPO_URLS} ${REPO_URLS} 180 fi 181 """ 182 archiveArtifacts artifacts: "**/${REPO_URLS},**/verrazzano_*.txt,**/${ARCHIVE_SOURCE_OUT},**/${DOWNLOAD_SOURCE_OUT}", allowEmptyArchive: true 183 } 184 cleanup { 185 deleteDir() 186 } 187 } 188 }