This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into feature/override-…
…notify-message-template * upstream/master: Fix build status and adjust Vault (#1074) Remove super-linter since it takes 20 minutes (#1083) Bump elastic stack version automation (#1081) feat: step to check if a docker image exists (#1077) docs: update CHANGELOG.md [maven-release-plugin] prepare for next development iteration [maven-release-plugin] prepare release v1.1.210 Enable stage filter argument for the beatsStages (#1076)
- Loading branch information
Showing
21 changed files
with
731 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import groovy.transform.Field | ||
|
||
@Library('apm@current') _ | ||
|
||
// To store all the latest snapshot versions | ||
@Field def latestVersions | ||
|
||
pipeline { | ||
agent { label 'linux && immutable' } | ||
environment { | ||
REPO = 'observability-dev' | ||
HOME = "${env.WORKSPACE}" | ||
NOTIFY_TO = credentials('notify-to') | ||
PIPELINE_LOG_LEVEL='INFO' | ||
} | ||
options { | ||
timeout(time: 1, unit: 'HOURS') | ||
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20')) | ||
timestamps() | ||
ansiColor('xterm') | ||
disableResume() | ||
durabilityHint('PERFORMANCE_OPTIMIZED') | ||
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) | ||
quietPeriod(10) | ||
} | ||
parameters { | ||
booleanParam(name: 'DRY_RUN_MODE', defaultValue: false, description: 'If true, allows to execute this pipeline in dry run mode, without sending a PR.') | ||
} | ||
stages { | ||
stage('Checkout') { | ||
steps { | ||
git(credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken', url: "https://github.com/elastic/${REPO}.git") | ||
} | ||
} | ||
stage('Fetch latest versions') { | ||
steps { | ||
script { | ||
latestVersions = artifactsApi(action: 'latest-versions') | ||
} | ||
archiveArtifacts 'latest-versions.json' | ||
} | ||
} | ||
stage('Send Pull Request'){ | ||
options { | ||
warnError('Pull Requests failed') | ||
} | ||
steps { | ||
generateSteps() | ||
} | ||
} | ||
} | ||
post { | ||
cleanup { | ||
notifyBuildResult() | ||
} | ||
} | ||
} | ||
|
||
def generateSteps(Map args = [:]) { | ||
def projects = readYaml(file: '.ci/.bump-stack-version.yml') | ||
def parallelTasks = [:] | ||
projects['projects'].each { project -> | ||
matrix( agent: 'linux && immutable', | ||
axes:[ | ||
axis('REPO', [project.repo]), | ||
axis('BRANCH', project.branches), | ||
axis('ENABLED', [project.get('enabled', true)]) | ||
], | ||
excludes: [ axis('ENABLED', [ false ]) ] | ||
) { | ||
bumpStackVersion(repo: env.REPO, | ||
scriptFile: "${project.script}", | ||
branch: env.BRANCH, | ||
reusePullRequest: project.get('reusePullRequest', false), | ||
labels: project.get('labels', '')) | ||
} | ||
} | ||
} | ||
|
||
def bumpStackVersion(Map args = [:]){ | ||
def repo = args.containsKey('repo') ? args.get('repo') : error('bumpStackVersion: repo argument is required') | ||
def scriptFile = args.containsKey('scriptFile') ? args.get('scriptFile') : error('bumpStackVersion: scriptFile argument is required') | ||
def branch = args.containsKey('branch') ? args.get('branch') : error('bumpStackVersion: branch argument is required') | ||
def reusePullRequest = args.get('reusePullRequest', false) | ||
def labels = args.get('labels', '') | ||
log(level: 'INFO', text: "bumpStackVersion(repo: ${repo}, branch: ${branch}, scriptFile: ${scriptFile}, reusePullRequest: ${reusePullRequest}, labels: '${labels}')") | ||
|
||
def branchName = findBranch(branch: branch, versions: latestVersions) | ||
def versionEntry = latestVersions.get(branchName) | ||
def message = createPRDescription(versionEntry) | ||
|
||
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { | ||
deleteDir() | ||
setupAPMGitEmail(global: true) | ||
git(url: "https://github.com/elastic/${repo}.git", branch: branchName, credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken') | ||
sh(script: "${scriptFile} '${versionEntry.build_id}'", label: "Prepare changes for ${repo}") | ||
|
||
pullRequest(reusePullRequest: reusePullRequest, | ||
stackVersion: versionEntry.build_id, | ||
message: message, | ||
labels: labels) | ||
} | ||
} | ||
|
||
def pullRequest(Map args = [:]){ | ||
def stackVersion = args.stackVersion | ||
def message = args.message | ||
def labels = args.labels.replaceAll('\\s','') | ||
def reusePullRequest = args.get('reusePullRequest', false) | ||
if (labels.trim()) { | ||
labels = "automation,${labels}" | ||
} | ||
|
||
if (params.DRY_RUN_MODE) { | ||
log(level: 'INFO', text: "DRY-RUN: pullRequest(stackVersion: ${stackVersion}, reusePullRequest: ${reusePullRequest}, labels: ${labels}, message: '${message}')") | ||
return | ||
} | ||
|
||
if (reusePullRequest && ammendPullRequestIfPossible()) { | ||
log(level: 'INFO', text: 'Reuse existing Pull Request') | ||
return | ||
} | ||
githubCreatePullRequest(title: "bump: stack version '${stackVersion}'", | ||
labels: "${labels}", description: "${message}") | ||
} | ||
|
||
def ammendPullRequestIfPossible() { | ||
log(level: 'INFO', text: 'TBD') | ||
return false | ||
} | ||
|
||
def findBranch(Map args = [:]){ | ||
def branch = args.branch | ||
// special macro to look for the latest minor version | ||
if (branch.contains('<minor>')) { | ||
def parts = branch.split('\\.') | ||
def major = parts[0] | ||
branch = args.versions.collect{ k,v -> k }.findAll { it ==~ /${major}\.\d+/}.sort().last() | ||
} | ||
return branch | ||
} | ||
|
||
def createPRDescription(versionEntry) { | ||
return """ | ||
### What | ||
Bump stack version with the latest one. | ||
### Further details | ||
``` | ||
${versionEntry} | ||
``` | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
- job: | ||
name: apm-shared/bump-stack-version-pipeline | ||
display-name: Bump Stack Version | ||
description: Send PRs to the subscribed observability repositories if a new stack snapshot version has been released. | ||
view: APM-CI | ||
project-type: pipeline | ||
parameters: | ||
- string: | ||
name: branch_specifier | ||
default: master | ||
description: the Git branch specifier to build | ||
pipeline-scm: | ||
script-path: .ci/bumpStackVersion.groovy | ||
scm: | ||
- git: | ||
url: git@github.com:elastic/apm-pipeline-library.git | ||
refspec: +refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/* | ||
wipe-workspace: 'True' | ||
name: origin | ||
shallow-clone: true | ||
credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba | ||
reference-repo: /var/lib/jenkins/.git-references/apm-pipeline-library.git | ||
branches: | ||
- $branch_specifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env bash | ||
# Licensed to Elasticsearch B.V. under one or more contributor | ||
# license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright | ||
# ownership. Elasticsearch B.V. licenses this file to you under | ||
# the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http:#www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# | ||
# It queries the artifacts-api entry point to fetch all the existing | ||
# snapshot versions and their metadata | ||
# It prints the output in the console in addition to the file | ||
# latest-versions.json | ||
# | ||
# Since it prints the output in the console avoid any cosmetic changes | ||
# with echo or set -x | ||
# | ||
set -eo pipefail | ||
|
||
URL="https://artifacts-api.elastic.co/v1" | ||
OUTPUT=latest-versions.json | ||
|
||
QUERY_OUTPUT=$(curl -s ${URL}/versions | jq -r '.aliases[] | select(contains("SNAPSHOT"))') | ||
LENGTH=$(echo $QUERY_OUTPUT | wc -l) | ||
i=0 | ||
echo "{" > "${OUTPUT}" | ||
for version in ${QUERY_OUTPUT}; do | ||
## Array separator | ||
i=$(($i + 1)) | ||
comma="" | ||
if [ ${i} -gt 1 ] ; then | ||
comma="," | ||
elif [ ${i} -ge ${LENGTH} ] ; then | ||
comma="" | ||
fi | ||
LATEST_OUTPUT=$(curl -s ${URL}/versions/${version}/builds/latest | jq 'del(.build.projects,.manifests) | . |= .build') | ||
BRANCH=$(echo $LATEST_OUTPUT | jq -r .branch) | ||
{ | ||
echo "${comma}\"$BRANCH\":" | ||
echo "${LATEST_OUTPUT}" | ||
} >> "${OUTPUT}" | ||
done | ||
echo "}" >> "${OUTPUT}" | ||
|
||
cat "${OUTPUT}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import org.junit.Before | ||
import org.junit.Test | ||
import static org.junit.Assert.assertFalse | ||
import static org.junit.Assert.assertTrue | ||
|
||
class ArtifactsApiStepTests extends ApmBasePipelineTest { | ||
|
||
@Override | ||
@Before | ||
void setUp() throws Exception { | ||
super.setUp() | ||
script = loadScript('vars/artifactsApi.groovy') | ||
} | ||
|
||
@Test | ||
void testWindows() throws Exception { | ||
testWindows() { | ||
script.call() | ||
} | ||
} | ||
|
||
@Test | ||
void test_missing_action() throws Exception { | ||
testMissingArgument('action') { | ||
script.call() | ||
} | ||
} | ||
|
||
@Test | ||
void test_unsupported_action() throws Exception { | ||
try { | ||
script.call(action: 'unknown') | ||
} catch(e) { | ||
//NOOP | ||
} | ||
printCallStack() | ||
assertTrue(assertMethodCallContainsPattern('error', "artifactsApi: unsupported action.")) | ||
assertJobStatusFailure() | ||
} | ||
|
||
@Test | ||
void test_latest_versions() throws Exception { | ||
helper.registerAllowedMethod('sh', [Map.class],{''' | ||
{ | ||
"6.8": | ||
{ | ||
"release_branch": "6.8", | ||
"branch": "6.8", | ||
"version": "6.8.16-SNAPSHOT", | ||
"build_id": "6.8.16-ac54b152" | ||
}, | ||
"7.x": | ||
{ | ||
"release_branch": "7.x", | ||
"branch": "7.x", | ||
"version": "7.13.0-SNAPSHOT", | ||
"build_id": "7.13.0-a6f186fd" | ||
} | ||
}'''}) | ||
def obj = script.call(action: 'latest-versions') | ||
assertTrue(obj.get('6.8').branch.equals('6.8')) | ||
printCallStack() | ||
} | ||
} |
Oops, something went wrong.