Skip to content

Commit 60155ab

Browse files
committed
update release scripts from master
1 parent d3e510e commit 60155ab

File tree

7 files changed

+187
-48
lines changed

7 files changed

+187
-48
lines changed

.ci/jobs/apm-agent-java-mbp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@
4242
reference-repo: /var/lib/jenkins/.git-references/apm-agent-java.git
4343
use-author: true
4444
wipe-workspace: true
45-
periodic-folder-trigger: 1h
45+
periodic-folder-trigger: 4h

.ci/release/Jenkinsfile

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@Library('apm@current') _
44
pipeline {
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 $fullUrl >/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 $TAG_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
}

.ci/release/update_cloudfoundry.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
REMOTE_NAME=origin
7+
BRANCH_NAME=master
8+
BASE_URL=https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent
9+
CF_FILE=cloudfoundry/index.yml
10+
11+
check_version "${1:-}"
12+
v="${1:-}"
13+
14+
echo -e "\n--- fetch & ensure clean state of ${REMOTE_NAME}/${BRANCH_NAME}"
15+
git fetch ${REMOTE_NAME} ${BRANCH_NAME}
16+
git checkout ${BRANCH_NAME}
17+
git reset --hard ${REMOTE_NAME}/${BRANCH_NAME}
18+
19+
echo -e "\n--- update ${CF_FILE} if required"
20+
21+
# make script idempotent if release is already in CF descriptor
22+
set +e
23+
grep -e "^${v}:" ${CF_FILE}
24+
[[ $? == 0 ]] && exit 0
25+
set -e
26+
27+
echo "${v}: ${BASE_URL}/${v}/elastic-apm-agent-${v}.jar" >> ${CF_FILE}
28+
git commit ${CF_FILE} -m "Update cloudfoundry for ${v} release"

.ci/release/update_major_branch.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
REMOTE_NAME=origin
7+
8+
# Final state (when there is no error): local checkout in the major branch '1.x' that matches the release tag
9+
# Pushing to remote repository is managed by the caller
10+
11+
check_version "${1:-}"
12+
v="${1:-}"
13+
14+
tag=$(version_tag ${v})
15+
major_branch="$(version_major_branch "${v}")"
16+
17+
echo ""
18+
echo "release version: ${v}"
19+
echo "release tag: ${tag}"
20+
echo "major branch: ${major_branch}"
21+
22+
check_ref_exists () {
23+
set +e
24+
git show-ref --verify --quiet "${1}" \
25+
&& echo 1 \
26+
|| echo 0
27+
set -e
28+
}
29+
30+
31+
# shallow clone does not allow to use other branches by default
32+
# found in https://stackoverflow.com/questions/23708231/git-shallow-clone-clone-depth-misses-remote-branches
33+
git remote set-branches ${REMOTE_NAME} '*'
34+
35+
echo -e "\n--- delete any local ${major_branch} branch if it exists"
36+
set +e
37+
git rev-parse --verify ${major_branch} 2>/dev/null && git branch -D ${major_branch}
38+
set -e
39+
40+
echo -e "\n--- ensure remote tag ${tag} and branch ${major_branch} are fetched for local checkout"
41+
git fetch --tags ${REMOTE_NAME}
42+
43+
if [[ '1' != $(check_ref_exists "refs/tags/${tag}") ]]; then
44+
echo "ERROR remote tag '${tag}' does not exists on remote '${REMOTE_NAME}'"
45+
exit 1
46+
fi
47+
48+
checkout_options=''
49+
50+
echo -e "\n--- checkout or create ${major_branch} branch"
51+
if [[ "0" == "$(check_ref_exists "refs/remotes/${REMOTE_NAME}/${major_branch}")" ]]; then
52+
# remote branch does not exists, creating new local branch
53+
checkout_options="-b ${major_branch}"
54+
else
55+
# remote branch exists, create local branch to update it
56+
checkout_options="--track ${REMOTE_NAME}/${major_branch}"
57+
fi
58+
set -e
59+
60+
echo -e "\n--- checkout local ${major_branch} branch"
61+
git checkout --force ${checkout_options}
62+
63+
echo -e "\n--- move local branch ${major_branch} to match tag ${tag}"
64+
git reset --hard ${tag}

.ci/release/util.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
check_version() {
4+
v=${1:-}
5+
6+
if [[ "${v}" == "" ]]; then
7+
echo "usage $0 <version>" # here $0 will be the calling script
8+
echo "where <version> in format '1.2.3'"
9+
exit 1
10+
fi
11+
12+
if [[ ! "$v" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
13+
echo "invalid version format '${v}'"
14+
exit 1
15+
fi
16+
}
17+
18+
version_tag() {
19+
echo "v${1:?usage version_tag <version>}"
20+
}
21+
22+
version_major_branch() {
23+
v="${1:?usage version_major_branch <version>}"
24+
echo "${v%%.*}.x"
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
# returns '0' (zero) status code when artifact exists
7+
# return non-zero status when artifact does not exists or unable to execute request
8+
9+
check_version "${1:-}"
10+
v="${1:-}"
11+
12+
full_url="https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/${v}/elastic-apm-agent-${v}.pom"
13+
curl -fs "${full_url}" 2>&1 > /dev/null
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
source "$(dirname "${0}")/util.sh"
5+
6+
# returns '0' (zero) status code when release notes have been published
7+
# return non-zero status when they haven't been published yet or unable to execute request
8+
9+
check_version "${1:-}"
10+
v="${1:-}"
11+
major_branch="$(version_major_branch "${v}")"
12+
13+
full_url="https://www.elastic.co/guide/en/apm/agent/java/current/release-notes-${major_branch}.html"
14+
curl -fs "${full_url}" | grep "${v}"

0 commit comments

Comments
 (0)