22
33@Library (' apm@current' ) _
44pipeline {
5- agent { label ' linux && immutable' }
5+ agent { label ' ubuntu && linux- immutable-docker ' }
66 environment {
77 REPO = ' apm-agent-java'
88 BASE_DIR = " src/github.com/elastic/${ env.REPO} "
@@ -23,7 +23,6 @@ pipeline {
2323 timestamps()
2424 ansiColor(' xterm' )
2525 durabilityHint(' PERFORMANCE_OPTIMIZED' )
26-
2726 }
2827 parameters {
2928 string(name : ' branch_specifier' , defaultValue : ' stable' , description : " What branch to release from?" )
@@ -45,17 +44,9 @@ pipeline {
4544 dir(" ${ BASE_DIR} " ) {
4645 setupAPMGitEmail()
4746 }
48-
49- dir(" ${ BASE_DIR} " ) {
50- script {
51- env. TAG_BARE = sh(script : " ./scripts/jenkins/tags.sh bare" , returnStdout : true )
52- env. TAG_VER = sh(script : " ./scripts/jenkins/tags.sh ver" , returnStdout : true )
53- env. TAG_DOT_X = sh(script : " ./scripts/jenkins/tags.sh dot_x" , returnStdout : true )
54- }
55- }
5647 dir(" ${ BASE_DIR} " ) {
57- withEnv([" BRANCH_NAME=tags/ ${ env.TAG_BARE } " ]){
58- withGitRelease() {
48+ withEnv([" BRANCH_NAME=${ BRANCH_SPECIFIER } " ]){
49+ withGitRelease() { // sets up the git release setup (remote branches, current workspace state, ...)
5950 stash(allowEmpty : true , name : ' source' , useDefaultExcludes : false )
6051 }
6152 }
@@ -88,12 +79,14 @@ pipeline {
8879 when {
8980 allOf {
9081 expression { params. check_branch_ci_status }
91- not { branch ' stable' }
82+ expression { env . BRANCH_SPECIFIER != ' stable' }
9283 }
9384 }
9485 steps {
9586 // If this build is not green: https://apm-ci.elastic.co/job/apm-agent-java/job/apm-agent-java-mbp/job/"${BRANCH_SPECIFIER}"/
9687 whenTrue(! buildStatus(host : ' apm-ci.elastic.co' , job : [' apm-agent-java' , ' apm-agent-java-mbp' , " ${ BRANCH_SPECIFIER} " ], return_boolean : true )) {
88+ notifyStatus(slackStatus : ' warning' , subject : " [${ env.REPO} ] The ${ BRANCH_SPECIFIER} build is not passing" ,
89+ body : " Please go to (<${ env.BUILD_URL} input|here>) to approve or reject within 12 hours." )
9790 input(message : " WARNING! The ${ BRANCH_SPECIFIER} build is not passing. Do you wish to continue?" )
9891 }
9992 }
@@ -125,6 +118,7 @@ pipeline {
125118 defaultValue : " ${ release_version} " ,
126119 description : " Current project version is ${ snapshot_version} , will be released as ${ release_version} if unchanged. Input release version without '-SNAPSHOT' suffix"
127120 ]])
121+
128122 if ( release_version. equals(user_release_version) ) {
129123 echo " changing project version '${ snapshot_version} ' not required to release ${ release_version} "
130124 } else {
@@ -133,6 +127,10 @@ pipeline {
133127 sh(script : " git commit -a -m 'Version bump ${ user_release_version} '" )
134128 gitPush()
135129 }
130+
131+ env. RELEASE_TAG = " v" + user_release_version
132+ env. RELEASE_VERSION = user_release_version
133+ env. BRANCH_DOT_X = user_release_version. substring(0 , user_release_version. indexOf(' .' ))+ ' .x'
136134 }
137135 }
138136 }
@@ -146,42 +144,39 @@ pipeline {
146144 }
147145 stage(' Nexus release' ) {
148146 steps {
149- script {
150- dir(" ${ BASE_DIR} " ){
151- withSecretVault(secret : ' secret/apm-team/ci/nexus' , user_var_name : ' __unused__' , pass_var_name : ' SPID' , role_id : ' apm-vault-role-id' , secret_id : ' apm-vault-secret-id' ){
152- def foundStagingId = nexusFindStagingId(stagingProfileId : " ${ SPID} " , groupId : " co.elastic.apm" )
153- nexusCloseStagingRepository(stagingProfileId : " ${ SPID} " , stagingId : foundStagingId)
154- nexusReleaseStagingRepository(stagingProfileId : " ${ SPID} " , stagingId : foundStagingId)
155- }
156- }
157- }
147+ notifyStatus(slackStatus : ' warning' , subject : " [${ env.REPO} ] Release ready to be published in Nexus" ,
148+ body : " Please go to (<https://oss.sonatype.org/|here>) to proceed with the manual nexus release. Login details in LastPass" )
149+ input(message : " Go to https://oss.sonatype.org and proceed with the steps to close and release the staging artifact." )
158150 }
159151 }
160- stage(' Branch creation ' ) {
152+ stage(' Major Branch create/update ' ) {
161153 steps {
162154 dir(" ${ BASE_DIR} " ) {
163155 script {
164- def curVer = mvnVersion()
165- sh(script : " ./scripts/jenkins/branch_creation.sh ${ curVer} " )
166- def isMajor = sh(script : " ./scripts/jenkins/is_major.sh ${ curVer} " , returnStatus : true )
167- if (isMajor == 0 ) {
156+ sh(script : " .ci/release/update_major_branch.sh ${ RELEASE_VERSION} " )
157+ gitPush(args : " -f ${ BRANCH_DOT_X} " )
158+
159+ def isMajor = env. RELEASE_VERSION . endsWith(" .0.0" )
160+ if (isMajor) {
168161 input message : " This was a major version release. Please update the conf.yml in the docs repo before continuing" , ok " Continue"
169162 }
170163 }
171- gitPush()
172164 }
173165 }
174166 }
175167 stage(' Create GitHub release draft' ) {
176168 steps {
177169 dir(" ${ BASE_DIR} " ){
178170 script {
179- def curVer = mvnVersion(showQualifiers : false )
180171 // Construct the URL with anchor for the release notes
181172 // Ex: https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-1.x.html#release-notes-1.13.0
182- def finalUrl = sh( script : " scripts/jenkins/generate_release_notes_url.sh ${ curVer } " , returnStdout : true )
173+ def finalUrl = " https://www.elastic.co/guide/en/apm/agent/java/current/release-notes- ${ BRANCH_DOT_X } .html#release-notes- ${ RELEASE_VERSION } "
183174 githubEnv()
184- def ret = githubReleaseCreate(draft : true , name : " Release ${ curVer} " , body : " [Release Notes for ${ curVer} ](${ finalUrl} )" )
175+ def ret = githubReleaseCreate(
176+ draft : true ,
177+ tagName : " ${ RELEASE_TAG} " ,
178+ releaseName : " Release ${ RELEASE_VERSION} " ,
179+ body : " [Release Notes for ${ RELEASE_VERSION} ](${ finalUrl} )" )
185180 env. RELEASE_ID = ret[' id' ]
186181 env. RELEASE_NOTES_URL = finalUrl
187182 }
@@ -192,12 +187,9 @@ pipeline {
192187 steps {
193188 dir(" ${ BASE_DIR} " ){
194189 script {
195- def fullUrl = sh(script : " ./scripts/jenkins/maven_artifact_url.sh " )
196- echo " Sleeping for ten minutes to wait for Sonatype"
197- sleep(time : 10 , unit : " MINUTES" )
198190 waitUntil(initialRecurrencePeriod : 60000 ) {
199191 script {
200- def ret = sh(script : " curl -fs $f ullUrl >/dev/null 2>&1 " , returnStatus : true )
192+ def ret = sh(script : " .ci/release/wait_maven_artifact_published.sh ${ RELEASE_VERSION } " , returnStatus : true )
201193 echo " Waiting for the artifacts to be published on Sonatype"
202194 return ret == 0
203195 }
@@ -209,38 +201,41 @@ pipeline {
209201 stage(' Update Cloudfoundry' ) {
210202 steps {
211203 dir(" ${ BASE_DIR} " ){
212- sh(script : " ./scripts/jenkins/ update_cloudfoundry.sh" )
204+ sh(script : " .ci/release/ update_cloudfoundry.sh ${ RELEASE_VERSION } " )
213205 gitPush()
214206 }
215207 }
216208 }
217209 stage(' Publish release on GitHub' ) {
218210 steps {
219- waitUntil( initialRecurrencePeriod : 60000 ) {
220- dir( " ${ BASE_DIR } " ) {
211+ dir( " ${ BASE_DIR } " ) {
212+ waitUntil( initialRecurrencePeriod : 60000 ) {
221213 script {
222214 echo " Waiting for the release notes to be available"
223- def ret = sh(script : " ./scripts/jenkins/docs_check .sh $T AG_VER " )
224- return ret == 0
215+ def ret = sh(script : " .ci/release/wait_release_notes_published .sh ${ RELEASE_VERSION } " , returnStatus : true )
216+ return ret == 0
225217 }
226218 }
219+ githubEnv()
220+ githubReleasePublish(id : " ${ env.RELEASE_ID} " , name : " Release ${ RELEASE_VERSION} " )
227221 }
228- githubEnv()
229- githubReleasePublish(id : " ${ env.RELEASE_ID} " )
230222 }
231223 }
232224 stage(' Build and push Docker images' ) {
233225 steps {
234226 dir(" ${ BASE_DIR} " ){
235- sh(label : " Build Docker image" , script : " ./scripts/jenkins/build_docker.sh" )
236- // Get Docker registry credentials
237- dockerLogin(secret : " ${ ELASTIC_DOCKER_SECRET} " , registry : ' docker.elastic.co' )
238- sh(label : " Push Docker image" , script : " ./scripts/jenkins/push_docker.sh" )
227+ // fetch agent artifact from remote repository
228+ withEnv([" SONATYPE_FALLBACK=1" ]) {
229+ sh(label : " Build Docker image" , script : " ./scripts/jenkins/build_docker.sh" )
230+ // Get Docker registry credentials
231+ dockerLogin(secret : " ${ ELASTIC_DOCKER_SECRET} " , registry : ' docker.elastic.co' , role_id : ' apm-vault-role-id' , secret_id : ' apm-vault-secret-id' )
232+ sh(label : " Push Docker image" , script : " ./scripts/jenkins/push_docker.sh" )
233+ }
239234 }
240235 }
241236 post {
242237 success {
243- notifyStatus(slackStatus : ' good' , subject : " [${ env.REPO} ] Release published" , body : " Great news! The release has completed successfully. (<${ env.RUN_DISPLAY_URL} |Open>)." )
238+ notifyStatus(slackStatus : ' good' , subject : " [${ env.REPO} ] Release published" , body : " Great news! The release ${ env.RELEASE_VERSION } has completed successfully. (<${ env.RUN_DISPLAY_URL} |Open>)." )
244239 }
245240 }
246241 }
0 commit comments