github.com/verrazzano/verrazzano@v1.7.0/JenkinsfileCopyrightTest (about) 1 // Copyright (c) 2020, 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 // This is temporary, to experiment with the Git settings in the Jenkins pipelines 5 6 def DOCKER_IMAGE_TAG 7 def SKIP_ACCEPTANCE_TESTS = false 8 9 pipeline { 10 options { 11 skipDefaultCheckout true 12 } 13 14 agent { 15 docker { 16 image "${RUNNER_DOCKER_IMAGE}" 17 args "${RUNNER_DOCKER_ARGS}" 18 registryUrl "${RUNNER_DOCKER_REGISTRY_URL}" 19 registryCredentialsId 'ocir-pull-and-push-account' 20 label "large" 21 } 22 } 23 24 parameters { 25 booleanParam (description: 'Whether to kick off acceptance test run at the end of this build', name: 'RUN_ACCEPTANCE_TESTS', defaultValue: true) 26 booleanParam (description: 'Whether to run example tests', name: 'RUN_EXAMPLE_TESTS', defaultValue: true) 27 booleanParam (description: 'Whether to dump k8s cluster on success (off by default can be useful to capture for comparing to failed cluster)', name: 'DUMP_K8S_CLUSTER_ON_SUCCESS', defaultValue: false) 28 } 29 30 environment { 31 DOCKER_PLATFORM_CI_IMAGE_NAME = 'verrazzano-platform-operator-jenkins' 32 DOCKER_PLATFORM_PUBLISH_IMAGE_NAME = 'verrazzano-platform-operator' 33 DOCKER_PLATFORM_IMAGE_NAME = "${env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master' ? env.DOCKER_PLATFORM_PUBLISH_IMAGE_NAME : env.DOCKER_PLATFORM_CI_IMAGE_NAME}" 34 DOCKER_OAM_CI_IMAGE_NAME = 'verrazzano-application-operator-jenkins' 35 DOCKER_OAM_PUBLISH_IMAGE_NAME = 'verrazzano-application-operator' 36 DOCKER_OAM_IMAGE_NAME = "${env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master' ? env.DOCKER_OAM_PUBLISH_IMAGE_NAME : env.DOCKER_OAM_CI_IMAGE_NAME}" 37 CREATE_LATEST_TAG = "${env.BRANCH_NAME == 'master' ? '1' : '0'}" 38 GOPATH = '/home/opc/go' 39 GO_REPO_PATH = "${GOPATH}/src/github.com/verrazzano" 40 DOCKER_CREDS = credentials('github-packages-credentials-rw') 41 DOCKER_EMAIL = credentials('github-packages-email') 42 DOCKER_REPO = 'ghcr.io' 43 DOCKER_NAMESPACE = 'verrazzano' 44 NETRC_FILE = credentials('netrc') 45 SERVICE_KEY = credentials('PAGERDUTY_SERVICE_KEY') 46 47 CLUSTER_NAME = 'verrazzano' 48 POST_DUMP_FAILED_FILE = "${WORKSPACE}/post_dump_failed_file.tmp" 49 TESTS_EXECUTED_FILE = "${WORKSPACE}/tests_executed_file.tmp" 50 KUBECONFIG = "${WORKSPACE}/test_kubeconfig" 51 VERRAZZANO_KUBECONFIG = "${KUBECONFIG}" 52 OCR_CREDS = credentials('ocr-pull-and-push-account') 53 OCR_REPO = 'container-registry.oracle.com' 54 IMAGE_PULL_SECRET = 'verrazzano-container-registry' 55 INSTALL_CONFIG_FILE_KIND = "./tests/e2e/config/scripts/v1beta1/install-verrazzano-kind.yaml" 56 INSTALL_PROFILE = "dev" 57 VZ_ENVIRONMENT_NAME = "default" 58 59 WEBLOGIC_PSW = credentials('weblogic-example-domain-password') // Needed by ToDoList example test 60 DATABASE_PSW = credentials('todo-mysql-password') // Needed by ToDoList example test 61 } 62 63 stages { 64 stage('Clean workspace and checkout') { 65 steps { 66 sh """ 67 echo "${NODE_LABELS}" 68 """ 69 70 script { 71 checkout scm 72 } 73 sh """ 74 cp -f "${NETRC_FILE}" $HOME/.netrc 75 chmod 600 $HOME/.netrc 76 """ 77 78 script { 79 try { 80 sh """ 81 echo "${DOCKER_CREDS_PSW}" | docker login ${env.DOCKER_REPO} -u ${DOCKER_CREDS_USR} --password-stdin 82 """ 83 } catch(error) { 84 echo "docker login failed, retrying after sleep" 85 retry(4) { 86 sleep(30) 87 sh """ 88 echo "${DOCKER_CREDS_PSW}" | docker login ${env.DOCKER_REPO} -u ${DOCKER_CREDS_USR} --password-stdin 89 """ 90 } 91 } 92 } 93 script { 94 try { 95 sh """ 96 echo "${OCR_CREDS_PSW}" | docker login -u ${OCR_CREDS_USR} ${OCR_REPO} --password-stdin 97 """ 98 } catch(error) { 99 echo "OCR docker login failed, retrying after sleep" 100 retry(4) { 101 sleep(30) 102 sh """ 103 echo "${OCR_CREDS_PSW}" | docker login -u ${OCR_CREDS_USR} ${OCR_REPO} --password-stdin 104 """ 105 } 106 } 107 } 108 sh """ 109 rm -rf ${GO_REPO_PATH}/verrazzano 110 mkdir -p ${GO_REPO_PATH}/verrazzano 111 tar cf - . | (cd ${GO_REPO_PATH}/verrazzano/ ; tar xf -) 112 """ 113 114 script { 115 def props = readProperties file: '.verrazzano-development-version' 116 VERRAZZANO_DEV_VERSION = props['verrazzano-development-version'] 117 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 118 SHORT_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short=8 HEAD").trim() 119 DOCKER_IMAGE_TAG = "${VERRAZZANO_DEV_VERSION}-${TIMESTAMP}-${SHORT_COMMIT_HASH}" 120 } 121 } 122 } 123 124 // cd ${GO_REPO_PATH}/verrazzano 125 126 stage('Quality and Compliance Checks') { 127 when { not { buildingTag() } } 128 steps { 129 sh """ 130 echo "copyright scan" 131 echo "working directory" 132 pwd 133 git branch 134 git diff --name-only "@{2001-01-01}" "@{now}" 135 git diff origin/master --name-only 136 git log --since=01-01-2021 --name-only --oneline --pretty="format:" | sort -u 137 time make copyright-check 138 ./ci/scripts/check_if_clean_after_generate.sh 139 """ 140 } 141 } 142 } 143 144 post { 145 always { 146 script { 147 if ( fileExists(env.TESTS_EXECUTED_FILE) ) { 148 dumpVerrazzanoSystemPods() 149 dumpCattleSystemPods() 150 dumpNginxIngressControllerLogs() 151 dumpVerrazzanoPlatformOperatorLogs() 152 dumpVerrazzanoApplicationOperatorLogs() 153 dumpOamKubernetesRuntimeLogs() 154 dumpVerrazzanoApiLogs() 155 } 156 } 157 archiveArtifacts artifacts: '**/coverage.html,**/logs/**,**/verrazzano_images.txt,**/*cluster-snapshot*/**', allowEmptyArchive: true 158 junit testResults: '**/*test-result.xml', allowEmptyResults: true 159 160 sh """ 161 cd ${GO_REPO_PATH}/verrazzano/platform-operator 162 make delete-cluster 163 if [ -f ${POST_DUMP_FAILED_FILE} ]; then 164 echo "Failures seen during dumping of artifacts, treat post as failed" 165 exit 1 166 fi 167 """ 168 deleteDir() 169 } 170 failure { 171 script { 172 if (env.JOB_NAME == "verrazzano/master" || env.JOB_NAME ==~ "verrazzano/release-*" || env.BRANCH_NAME ==~ "mark/*") { 173 slackSend ( 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}" ) 174 } 175 } 176 } 177 } 178 } 179 180 def runGinkgoRandomize(testSuitePath) { 181 catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { 182 sh """ 183 cd ${GO_REPO_PATH}/verrazzano/tests/e2e 184 ginkgo -p --randomize-all -v --keep-going --no-color ${testSuitePath}/... 185 """ 186 } 187 } 188 189 def runGinkgo(testSuitePath) { 190 catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { 191 sh """ 192 cd ${GO_REPO_PATH}/verrazzano/tests/e2e 193 ginkgo -v --keep-going --no-color ${testSuitePath}/... 194 """ 195 } 196 } 197 198 def dumpK8sCluster(dumpDirectory) { 199 sh """ 200 mkdir -p ${dumpDirectory}/cluster-snapshot 201 ${GO_REPO_PATH}/verrazzano/tools/scripts/k8s-dump-cluster.sh -d ${dumpDirectory}/cluster-snapshot -r ${dumpDirectory}/cluster-snapshot/analysis.report 202 ${GO_REPO_PATH}/vz bug-report --report-file ${dumpDirectory}/bug-report.tar.gz 203 mkdir -p ${dumpDirectory}/bug-report 204 tar -xvf ${dumpDirectory}/bug-report.tar.gz -C ${dumpDirectory}/bug-report 205 """ 206 } 207 208 def dumpVerrazzanoSystemPods() { 209 sh """ 210 cd ${GO_REPO_PATH}/verrazzano/platform-operator 211 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-pods.log" 212 ./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -m "verrazzano system pods" || echo "failed" > ${POST_DUMP_FAILED_FILE} 213 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-certs.log" 214 ./scripts/install/k8s-dump-objects.sh -o cert -n verrazzano-system -m "verrazzano system certs" || echo "failed" > ${POST_DUMP_FAILED_FILE} 215 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-osd.log" 216 ./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -r "vmi-system-osd-*" -m "verrazzano system opensearchdashboards log" -l -c osd || echo "failed" > ${POST_DUMP_FAILED_FILE} 217 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-system-es-master.log" 218 ./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -r "vmi-system-es-master-*" -m "verrazzano system opensearchdashboards log" -l -c es-master || echo "failed" > ${POST_DUMP_FAILED_FILE} 219 """ 220 } 221 222 def dumpCattleSystemPods() { 223 sh """ 224 cd ${GO_REPO_PATH}/verrazzano/platform-operator 225 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/cattle-system-pods.log" 226 ./scripts/install/k8s-dump-objects.sh -o pods -n cattle-system -m "cattle system pods" || echo "failed" > ${POST_DUMP_FAILED_FILE} 227 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/rancher.log" 228 ./scripts/install/k8s-dump-objects.sh -o pods -n cattle-system -r "rancher-*" -m "Rancher logs" -l || echo "failed" > ${POST_DUMP_FAILED_FILE} 229 """ 230 } 231 232 def dumpNginxIngressControllerLogs() { 233 sh """ 234 cd ${GO_REPO_PATH}/verrazzano/platform-operator 235 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/nginx-ingress-controller.log" 236 ./scripts/install/k8s-dump-objects.sh -o pods -n ingress-nginx -r "nginx-ingress-controller-*" -m "Nginx Ingress Controller" -l || echo "failed" > ${POST_DUMP_FAILED_FILE} 237 """ 238 } 239 240 def dumpVerrazzanoPlatformOperatorLogs() { 241 sh """ 242 ## dump out verrazzano-platform-operator logs 243 mkdir -p ${WORKSPACE}/verrazzano-platform-operator/logs 244 kubectl -n verrazzano-install logs --selector=app=verrazzano-platform-operator > ${WORKSPACE}/verrazzano-platform-operator/logs/verrazzano-platform-operator-pod.log --tail -1 || echo "failed" > ${POST_DUMP_FAILED_FILE} 245 kubectl -n verrazzano-install describe pod --selector=app=verrazzano-platform-operator > ${WORKSPACE}/verrazzano-platform-operator/logs/verrazzano-platform-operator-pod.out || echo "failed" > ${POST_DUMP_FAILED_FILE} 246 echo "verrazzano-platform-operator logs dumped to verrazzano-platform-operator-pod.log" 247 echo "verrazzano-platform-operator pod description dumped to verrazzano-platform-operator-pod.out" 248 echo "------------------------------------------" 249 """ 250 } 251 252 def dumpVerrazzanoApplicationOperatorLogs() { 253 sh """ 254 ## dump out verrazzano-application-operator logs 255 mkdir -p ${WORKSPACE}/verrazzano-application-operator/logs 256 kubectl -n verrazzano-system logs --selector=app=verrazzano-application-operator > ${WORKSPACE}/verrazzano-application-operator/logs/verrazzano-application-operator-pod.log --tail -1 || echo "failed" > ${POST_DUMP_FAILED_FILE} 257 kubectl -n verrazzano-system describe pod --selector=app=verrazzano-application-operator > ${WORKSPACE}/verrazzano-application-operator/logs/verrazzano-application-operator-pod.out || echo "failed" > ${POST_DUMP_FAILED_FILE} 258 echo "verrazzano-application-operator logs dumped to verrazzano-application-operator-pod.log" 259 echo "verrazzano-application-operator pod description dumped to verrazzano-application-operator-pod.out" 260 echo "------------------------------------------" 261 """ 262 } 263 264 def dumpOamKubernetesRuntimeLogs() { 265 sh """ 266 ## dump out oam-kubernetes-runtime logs 267 mkdir -p ${WORKSPACE}/oam-kubernetes-runtime/logs 268 kubectl -n verrazzano-system logs --selector=app.kubernetes.io/instance=oam-kubernetes-runtime > ${WORKSPACE}/oam-kubernetes-runtime/logs/oam-kubernetes-runtime-pod.log --tail -1 || echo "failed" > ${POST_DUMP_FAILED_FILE} 269 kubectl -n verrazzano-system describe pod --selector=app.kubernetes.io/instance=oam-kubernetes-runtime > ${WORKSPACE}/verrazzano-application-operator/logs/oam-kubernetes-runtime-pod.out || echo "failed" > ${POST_DUMP_FAILED_FILE} 270 echo "verrazzano-application-operator logs dumped to oam-kubernetes-runtime-pod.log" 271 echo "verrazzano-application-operator pod description dumped to oam-kubernetes-runtime-pod.out" 272 echo "------------------------------------------" 273 """ 274 } 275 276 def dumpVerrazzanoApiLogs() { 277 sh """ 278 cd ${GO_REPO_PATH}/verrazzano/platform-operator 279 export DIAGNOSTIC_LOG="${WORKSPACE}/verrazzano/platform-operator/scripts/install/build/logs/verrazzano-authproxy.log" 280 ./scripts/install/k8s-dump-objects.sh -o pods -n verrazzano-system -r "verrazzano-authproxy-*" -m "verrazzano api" -l || echo "failed" > ${POST_DUMP_FAILED_FILE} 281 """ 282 }