-
Notifications
You must be signed in to change notification settings - Fork 116
Jenkins pipeline for sending PRs to agents when changing the BDD specs #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de5c757
14cc5c7
9008ffb
d9cca8c
8f2155d
ca7e0fb
96bf7f6
2b9b494
da7ce62
c62df02
27b14f6
a154543
bb85e67
ba0cba6
b65be94
8da3a39
34c1ce0
522bb6c
7698953
b9512f0
0f57f6a
c1cb41e
44f84ea
08f9d9a
d50d4ae
d2d7ed4
9ed5ddd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
agents: | ||
- NAME: "dotnet" | ||
FEATURES_PATH: "test/Elastic.Apm.Feature.Tests/Features" | ||
- NAME: "go" | ||
FEATURES_PATH: "features" | ||
- NAME: "java" | ||
FEATURES_PATH: "apm-agent-core/src/test/resources/specs" | ||
- NAME: "python" | ||
FEATURES_PATH: "tests/bdd/features" | ||
- NAME: "ruby" | ||
FEATURES_PATH: "features" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// 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. | ||
|
||
@Library('apm@current') _ | ||
|
||
pipeline { | ||
agent { label 'linux && immutable' } | ||
environment { | ||
REPO = 'apm' | ||
BASE_DIR = "src/github.com/elastic/${env.REPO}" | ||
HOME = "${env.WORKSPACE}" | ||
NOTIFY_TO = credentials('notify-to') | ||
JOB_GCS_BUCKET = credentials('gcs-bucket') | ||
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba" | ||
PATH = "${env.PATH}:${env.WORKSPACE}/bin" | ||
PIPELINE_LOG_LEVEL='INFO' | ||
} | ||
options { | ||
timeout(time: 3, unit: 'HOURS') | ||
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5')) | ||
timestamps() | ||
ansiColor('xterm') | ||
disableResume() | ||
durabilityHint('PERFORMANCE_OPTIMIZED') | ||
} | ||
parameters { | ||
booleanParam(name: 'Do_Send_PR', defaultValue: false, description: 'Allows to execute this pipeline in dry run mode, without sending a PR.') | ||
} | ||
stages { | ||
stage('Initializing'){ | ||
options { skipDefaultCheckout() } | ||
stages { | ||
stage('Checkout'){ | ||
steps { | ||
deleteDir() | ||
gitCheckout(basedir: "${BASE_DIR}", | ||
branch: "master", | ||
repo: "git@github.com:elastic/${REPO}.git", | ||
credentialsId: "${JOB_GIT_CREDENTIALS}" | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
stash allowEmpty: true, name: 'source', useDefaultExcludes: false | ||
script { | ||
dir("${BASE_DIR}"){ | ||
def regexps =[ | ||
"^tests/agents/gherkin-specs/" | ||
] | ||
env.GHERKIN_SPECS_UPDATED = isGitRegionMatch(patterns: regexps) | ||
} | ||
} | ||
Comment on lines
+56
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the block that controls if there are changes in the gherkin files. If so, the environment variable will be set to true, causing https://github.com/elastic/apm/pull/231/files#diff-8db37e8fcea0f1a8f2f39667e94ebcc4R76 to evaluate to true too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this, the script sending the PR has to add no logic for checking if changes exist, so it just follow orders from the pipeline. |
||
} | ||
} | ||
stage('Send Pull Request'){ | ||
options { | ||
skipDefaultCheckout() | ||
warnError('Pull Requests to APM agents failed') | ||
} | ||
environment { | ||
DO_SEND_PR = "${params.Do_Send_PR}" | ||
} | ||
when { | ||
beforeAgent true | ||
expression { return env.GHERKIN_SPECS_UPDATED != "false" } | ||
} | ||
steps { | ||
unstash 'source' | ||
dir("${BASE_DIR}"){ | ||
script { | ||
def agents = readYaml(file: '.ci/.jenkins-agents.yml') | ||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def parallelTasks = [:] | ||
agents['agents'].each { agent -> | ||
parallelTasks["apm-agent-${agent.NAME}"] = generateStepForAgent(agent: "${agent.NAME}", featuresPath: "${agent.FEATURES_PATH}") | ||
} | ||
|
||
parallel(parallelTasks) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
cleanup { | ||
notifyBuildResult() | ||
} | ||
} | ||
} | ||
|
||
def generateStepForAgent(Map params = [:]){ | ||
def agent = params.get('agent') | ||
def featuresPath = params.get('featuresPath') | ||
log(level: 'INFO', text: "agent=${agent} featuresPath=${featuresPath}") | ||
return { | ||
node('linux && immutable') { | ||
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { | ||
deleteDir() | ||
gitCmd(cmd: "config", credentialsId: '', args: '--global user.name elasticmachine') | ||
gitCmd(cmd: "config", credentialsId: '', args: '--global user.email infra-root-elasticmachine@elastic.co') | ||
unstash 'source' | ||
dir("${BASE_DIR}"){ | ||
sh script: '.ci/scripts/install-dependencies.sh', label: "Install dependencies" | ||
sh script: """.ci/scripts/send-pr.sh "${agent}" "${featuresPath}" """, label: "Send Pull Request for apm-agent-${agent}" | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -uexo pipefail | ||
|
||
readonly HUB_VERSION="2.14.2" | ||
readonly HUB_CMD="${HOME}/bin" | ||
|
||
# install GitHub's hub | ||
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s ${HUB_VERSION} | ||
mkdir -p ${HUB_CMD} | ||
mv bin/hub "${HUB_CMD}/hub" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -uexo pipefail | ||
|
||
readonly APM_AGENT=${1} | ||
readonly APM_AGENT_SPECS_DIR=${2} | ||
readonly APM_AGENT_REPO_NAME="apm-agent-${APM_AGENT}" | ||
readonly GIT_DIR=".ci/git" | ||
readonly APM_AGENT_REPO_DIR="${GIT_DIR}/${APM_AGENT_REPO_NAME}" | ||
|
||
mdelapenya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
git clone "https://github.com/elastic/${APM_AGENT_REPO_NAME}" "${APM_AGENT_REPO_DIR}" | ||
|
||
mkdir -p "${APM_AGENT_REPO_DIR}/${APM_AGENT_SPECS_DIR}" | ||
echo "Copying feature files to the ${APM_AGENT_REPO_NAME} repo" | ||
cp tests/agents/gherkin-specs/*.feature "${APM_AGENT_REPO_DIR}/${APM_AGENT_SPECS_DIR}" | ||
|
||
cd ${APM_AGENT_REPO_DIR} | ||
git checkout -b update-feature-files-$(date "+%Y%m%d%H%M%S") | ||
git add ${APM_AGENT_SPECS_DIR} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, the git user.name and user.email should be in place (see PR 17214 in the infra repo), if that's not the case, then you might get some warnings, or maybe some errors, although I don't recall now. I'd say to use some validation in case they are not defined to set them. what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a validation, I have added two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started with the check, but I realised that it is worth it to be prescriptive in this case, where we do not want other configuration. Just in case, that was my initial validation, at script level: readonly GIT_USERNAME="elasticmachine"
readonly GIT_EMAIL="infra-root-${GIT_USERNAME}@elastic.co"
function checkGitConfig {
local config="${1}"
local defaultValue="${2}"
git config "${config}"
local exitCode=$?
if [ ${exitCode} -ne 0 ]; then
git config "${config}" "${defaultValue}"
fi
}
function checkGit {
checkGitConfig "user.name" "${GIT_USERNAME}"
checkGitConfig "user.email" "${GIT_EMAIL}"
} |
||
git commit -m "test: synchronizing bdd specs" | ||
|
||
if [[ "${DO_SEND_PR}" == "true" ]]; then | ||
hub pull-request \ | ||
-p \ # push the branch to the remote | ||
--labels automation \ # comma-separated list of tags | ||
--reviewer @elastic/apm-agent-devs \ # set agents as reviewer of the PR | ||
-m "test: synchronizing bdd specs" # PR message | ||
else | ||
echo "PR sent to ${APM_AGENT_REPO_NAME}" | ||
fi |
Uh oh!
There was an error while loading. Please reload this page.