github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/Jenkinsfile (about) 1 // Copyright (c) 2020, 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 def DOCKER_IMAGE_TAG 5 6 pipeline { 7 options { 8 skipDefaultCheckout true 9 } 10 11 agent { 12 docker { 13 image "${RUNNER_DOCKER_IMAGE}" 14 args "${RUNNER_DOCKER_ARGS}" 15 registryUrl "${RUNNER_DOCKER_REGISTRY_URL}" 16 registryCredentialsId 'ocir-pull-and-push-account' 17 } 18 } 19 20 environment { 21 DOCKER_CI_IMAGE_NAME_OPERATOR = 'verrazzano-monitoring-operator-jenkins' 22 DOCKER_PUBLISH_IMAGE_NAME_OPERATOR = 'verrazzano-monitoring-operator' 23 DOCKER_IMAGE_NAME_OPERATOR = "${env.BRANCH_NAME ==~ /^release-.*/ || env.BRANCH_NAME == 'master' ? env.DOCKER_PUBLISH_IMAGE_NAME_OPERATOR : env.DOCKER_CI_IMAGE_NAME_OPERATOR}" 24 25 DOCKER_CI_IMAGE_NAME_ESWAIT = 'verrazzano-monitoring-instance-eswait-jenkins' 26 DOCKER_PUBLISH_IMAGE_NAME_ESWAIT = 'verrazzano-monitoring-instance-eswait' 27 DOCKER_IMAGE_NAME_ESWAIT = "${env.BRANCH_NAME == 'master' ? env.DOCKER_PUBLISH_IMAGE_NAME_ESWAIT : env.DOCKER_CI_IMAGE_NAME_ESWAIT}" 28 29 CREATE_LATEST_TAG = "${env.BRANCH_NAME == 'master' ? '1' : '0'}" 30 GOPATH = '/home/opc/go' 31 GO_REPO_PATH = "${GOPATH}/src/github.com/verrazzano" 32 DOCKER_CREDS = credentials('github-packages-credentials-rw') 33 DOCKER_REPO = 'ghcr.io' 34 DOCKER_NAMESPACE = 'verrazzano' 35 HELM_CHART_NAME = 'verrazzano-monitoring-operator' 36 VMI_NAMESAPCE_PREFIX = 'vmi' 37 ELASTICSEARCH_VERSION = '7.2.0' 38 INGRESS_NODE_PORT = sh(script: "shuf -i 30000-32767 -n 1" , returnStdout: true) 39 KUBECONFIG = '~/.kube/config' 40 NETRC_FILE = credentials('netrc') 41 } 42 43 stages { 44 stage('Clean workspace and checkout') { 45 steps { 46 checkout scm 47 sh """ 48 cp -f "${NETRC_FILE}" $HOME/.netrc 49 chmod 600 $HOME/.netrc 50 """ 51 sh """ 52 echo "${DOCKER_CREDS_PSW}" | docker login ${env.DOCKER_REPO} -u ${DOCKER_CREDS_USR} --password-stdin 53 rm -rf ${GO_REPO_PATH}/verrazzano-monitoring-operator 54 mkdir -p ${GO_REPO_PATH}/verrazzano-monitoring-operator 55 tar cf - . | (cd ${GO_REPO_PATH}/verrazzano-monitoring-operator/ ; tar xf -) 56 """ 57 script { 58 def props = readProperties file: '.verrazzano-development-version' 59 VERRAZZANO_DEV_VERSION = props['verrazzano-development-version'] 60 TIMESTAMP = sh(returnStdout: true, script: "date +%Y%m%d%H%M%S").trim() 61 SHORT_COMMIT_HASH = sh(returnStdout: true, script: "git rev-parse --short HEAD").trim() 62 DOCKER_IMAGE_TAG = "v${VERRAZZANO_DEV_VERSION}-${TIMESTAMP}-${SHORT_COMMIT_HASH}" 63 } 64 } 65 } 66 67 stage('Check Repo Clean') { 68 steps { 69 checkRepoClean() 70 } 71 } 72 73 stage('Build') { 74 when { not { buildingTag() } } 75 steps { 76 sh """ 77 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 78 make push DOCKER_IMAGE_NAME_OPERATOR=${DOCKER_IMAGE_NAME_OPERATOR} DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG} K8S_NAMESPACE=${VMI_NAMESAPCE_PREFIX}-${env.BUILD_NUMBER} CREATE_LATEST_TAG=${CREATE_LATEST_TAG} 79 """ 80 } 81 } 82 83 stage('golangci-lint Check') { 84 when { not { buildingTag() } } 85 steps { 86 sh """ 87 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 88 make golangci-lint 89 """ 90 } 91 } 92 93 stage('Third Party License Check') { 94 when { not { buildingTag() } } 95 steps { 96 thirdpartyCheck() 97 } 98 } 99 100 stage('Copyright Compliance Check') { 101 when { not { buildingTag() } } 102 steps { 103 copyrightScan "${WORKSPACE}" 104 } 105 } 106 107 stage('Unit Tests') { 108 when { not { buildingTag() } } 109 steps { 110 sh """ 111 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 112 make unit-test 113 make -B coverage 114 cp coverage.html ${WORKSPACE} 115 build/scripts/copy-junit-output.sh ${WORKSPACE} 116 """ 117 } 118 post { 119 always { 120 archiveArtifacts artifacts: '**/coverage.html', allowEmptyArchive: true 121 junit testResults: '**/*test-result.xml', allowEmptyResults: true 122 } 123 } 124 } 125 126 stage('Integration Tests') { 127 when { not { buildingTag() } } 128 steps { 129 sh """ 130 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 131 echo "To do.." 132 """ 133 } 134 } 135 136 stage('basic1 integ tests oke') { 137 when { not { buildingTag() } } 138 steps { 139 sh """ 140 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 141 echo "To do.." 142 """ 143 } 144 } 145 146 stage('basic2 integ tests oke') { 147 when { not { buildingTag() } } 148 steps { 149 sh """ 150 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 151 echo "To do.." 152 """ 153 } 154 } 155 156 stage('basic3 integ tests oke') { 157 when { not { buildingTag() } } 158 steps { 159 sh """ 160 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 161 echo "To do.." 162 """ 163 } 164 } 165 166 stage('basic4 integ tests oke') { 167 when { not { buildingTag() } } 168 steps { 169 sh """ 170 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 171 echo "To do.." 172 """ 173 } 174 } 175 176 stage('Scan Image') { 177 when { not { buildingTag() } } 178 steps { 179 script { 180 scanContainerImage "${env.DOCKER_REPO}/${env.DOCKER_NAMESPACE}/${DOCKER_IMAGE_NAME_OPERATOR}:${DOCKER_IMAGE_TAG}" 181 } 182 } 183 post { 184 always { 185 archiveArtifacts artifacts: '**/*scanning-report.json', allowEmptyArchive: true 186 } 187 } 188 } 189 } 190 191 post { 192 failure { 193 script { 194 if (env.BRANCH_NAME == "master" || env.BRANCH_NAME ==~ "release-.*" || env.BRANCH_NAME ==~ "mark/*") { 195 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}" ) 196 } 197 } 198 } 199 } 200 } 201 202 def checkRepoClean() { 203 sh """ 204 cd ${GO_REPO_PATH}/verrazzano-monitoring-operator 205 echo 'Check for forgotten manifest/generate actions...' 206 (make check-repo-clean) 207 """ 208 }