From 3008d87a9110f1160083859b97f1413cab0ba563 Mon Sep 17 00:00:00 2001 From: Ivan Fernandez Calvo Date: Wed, 1 Jul 2020 18:40:50 +0200 Subject: [PATCH] Cherry-pick #19490 #19559 to 7.7: ci: disable upstream trigger on PRs for the packaging job (#19545) * ci: correct upstream job * ci: filter build causes * Update .ci/packaging.groovy --- .ci/packaging.groovy | 222 +++++++++++++++++++++---------------------- 1 file changed, 109 insertions(+), 113 deletions(-) diff --git a/.ci/packaging.groovy b/.ci/packaging.groovy index e57433f8f69..4c1fa26ebdb 100644 --- a/.ci/packaging.groovy +++ b/.ci/packaging.groovy @@ -3,14 +3,16 @@ @Library('apm@current') _ pipeline { - agent { label 'ubuntu && immutable' } + agent none environment { BASE_DIR = 'src/github.com/elastic/beats' JOB_GCS_BUCKET = 'beats-ci-artifacts' + JOB_GCS_BUCKET_STASH = 'beats-ci-temp' JOB_GCS_CREDENTIALS = 'beats-ci-gcs-plugin' DOCKERELASTIC_SECRET = 'secret/observability-team/ci/docker-registry/prod' DOCKER_REGISTRY = 'docker.elastic.co' SNAPSHOT = "true" + PIPELINE_LOG_LEVEL = "INFO" } options { timeout(time: 3, unit: 'HOURS') @@ -22,98 +24,115 @@ pipeline { disableConcurrentBuilds() } triggers { - issueCommentTrigger('(?i)^\\/packaging$') - upstream('Beats/beats-beats-mbp/7.7') + issueCommentTrigger('(?i)^\\/packag[ing|e]$') + // disable upstream trigger on a PR basis + upstream("Beats/beats-beats-mbp/${ env.JOB_BASE_NAME.startsWith('PR-') ? 'none' : env.JOB_BASE_NAME }") } parameters { booleanParam(name: 'macos', defaultValue: false, description: 'Allow macOS stages.') booleanParam(name: 'linux', defaultValue: true, description: 'Allow linux stages.') } stages { - stage('Checkout') { - options { skipDefaultCheckout() } - steps { - deleteDir() - gitCheckout(basedir: "${BASE_DIR}") - setEnvVar("GO_VERSION", readFile("${BASE_DIR}/.go-version").trim()) - //stash allowEmpty: true, name: 'source', useDefaultExcludes: false + stage('Filter build') { + agent { label 'ubuntu && immutable' } + when { + beforeAgent true + expression { + return isCommentTrigger() || isUserTrigger() + } } - } - stage('Build Packages'){ - matrix { - axes { - axis { - name 'BEATS_FOLDER' - values ( - 'auditbeat', - 'filebeat', - 'heartbeat', - 'journalbeat', - 'metricbeat', - 'packetbeat', - 'winlogbeat', - 'x-pack/auditbeat', - 'x-pack/dockerlogbeat', - 'x-pack/filebeat', - 'x-pack/functionbeat', - // 'x-pack/heartbeat', - // 'x-pack/journalbeat', - 'x-pack/metricbeat', - // 'x-pack/packetbeat', - 'x-pack/winlogbeat' - ) + stages { + stage('Checkout') { + options { skipDefaultCheckout() } + steps { + deleteDir() + gitCheckout(basedir: "${BASE_DIR}") + setEnvVar("GO_VERSION", readFile("${BASE_DIR}/.go-version").trim()) + stashV2(name: 'source', bucket: "${JOB_GCS_BUCKET_STASH}", credentialsId: "${JOB_GCS_CREDENTIALS}") } } - stages { - stage('Package Linux'){ - agent { label 'ubuntu && immutable' } - options { skipDefaultCheckout() } - when { - beforeAgent true - expression { - return params.linux + stage('Build Packages'){ + matrix { + axes { + axis { + name 'BEATS_FOLDER' + values ( + 'auditbeat', + 'filebeat', + 'heartbeat', + 'journalbeat', + 'metricbeat', + 'packetbeat', + 'winlogbeat', + 'x-pack/auditbeat', + 'x-pack/elastic-agent', + 'x-pack/dockerlogbeat', + 'x-pack/filebeat', + 'x-pack/functionbeat', + // 'x-pack/heartbeat', + // 'x-pack/journalbeat', + 'x-pack/metricbeat', + // 'x-pack/packetbeat', + 'x-pack/winlogbeat' + ) } } - environment { - HOME = "${env.WORKSPACE}" - PLATFORMS = [ - '+all', - 'linux/amd64', - 'linux/386', - 'linux/arm64', - 'linux/armv7', - 'linux/ppc64le', - 'linux/mips64', - 'linux/s390x', - 'windows/amd64', - 'windows/386', - (params.macos ? '' : 'darwin/amd64'), - ].join(' ') - } - steps { - release() - pushCIDockerImages() - } - } - stage('Package Mac OS'){ - agent { label 'macosx' } - options { skipDefaultCheckout() } - when { - beforeAgent true - expression { - return params.macos + stages { + stage('Package Linux'){ + agent { label 'ubuntu && immutable' } + options { skipDefaultCheckout() } + when { + beforeAgent true + expression { + return params.linux + } + } + environment { + HOME = "${env.WORKSPACE}" + PLATFORMS = [ + '+all', + 'linux/amd64', + 'linux/386', + 'linux/arm64', + 'linux/armv7', + 'linux/ppc64le', + 'linux/mips64', + 'linux/s390x', + 'windows/amd64', + 'windows/386', + (params.macos ? '' : 'darwin/amd64'), + ].join(' ') + } + steps { + withGithubNotify(context: "Packaging Linux ${BEATS_FOLDER}") { + release() + pushCIDockerImages() + } + } } - } - environment { - HOME = "${env.WORKSPACE}" - PLATFORMS = [ - '+all', - 'darwin/amd64', - ].join(' ') - } - steps { - withMacOSEnv(){ - release() + stage('Package Mac OS'){ + agent { label 'macosx-10.12' } + options { skipDefaultCheckout() } + when { + beforeAgent true + expression { + return params.macos + } + } + environment { + HOME = "${env.WORKSPACE}" + PLATFORMS = [ + '+all', + 'darwin/amd64', + ].join(' ') + } + steps { + withGithubNotify(context: "Packaging MacOS ${BEATS_FOLDER}") { + withMacOSEnv(){ + release() + } + } + } } } } @@ -201,38 +220,15 @@ def publishPackages(baseDir){ } def withBeatsEnv(Closure body) { - def os = goos() - def goRoot = "${env.WORKSPACE}/.gvm/versions/go${GO_VERSION}.${os}.amd64" - - withEnv([ - "HOME=${env.WORKSPACE}", - "GOPATH=${env.WORKSPACE}", - "GOROOT=${goRoot}", - "PATH=${env.WORKSPACE}/bin:${goRoot}/bin:${env.PATH}", - "MAGEFILE_CACHE=${WORKSPACE}/.magefile", - "PYTHON_ENV=${WORKSPACE}/python-env" - ]) { - deleteDir() - //unstash 'source' - gitCheckout(basedir: "${BASE_DIR}") - dir("${env.BASE_DIR}"){ - sh(label: "Install Go ${GO_VERSION}", script: ".ci/scripts/install-go.sh") - sh(label: "Install Mage", script: "make mage") - body() + withMageEnv(){ + withEnv([ + "PYTHON_ENV=${WORKSPACE}/python-env" + ]) { + deleteDir() + unstashV2(name: 'source', bucket: "${JOB_GCS_BUCKET_STASH}", credentialsId: "${JOB_GCS_CREDENTIALS}") + dir("${env.BASE_DIR}"){ + body() + } } } } - -def goos(){ - def labels = env.NODE_LABELS - - if (labels.contains('linux')) { - return 'linux' - } else if (labels.contains('windows')) { - return 'windows' - } else if (labels.contains('darwin')) { - return 'darwin' - } - - error("Unhandled OS name in NODE_LABELS: " + labels) -}