Skip to content

Commit

Permalink
CI: enable AWS cloud testing on a PR basis if changes in certain files (
Browse files Browse the repository at this point in the history
#29047)

(cherry picked from commit 3dc0afb)
  • Loading branch information
v1v authored and mergify-bot committed Nov 25, 2021
1 parent 44b2232 commit 5f2e365
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ def generateStages(Map args = [:]) {
def cloud(Map args = [:]) {
withGithubNotify(context: args.context) {
withNode(labels: args.label, forceWorkspace: true){
startCloudTestEnv(name: args.directory, dirs: args.dirs)
startCloudTestEnv(name: args.directory, dirs: args.dirs, withAWS: args.withAWS)
}
withCloudTestEnv() {
withCloudTestEnv(args) {
try {
target(context: args.context, command: args.command, directory: args.directory, label: args.label, withModule: args.withModule, isMage: true, id: args.id)
} finally {
terraformCleanup(name: args.directory, dir: args.directory)
terraformCleanup(name: args.directory, dir: args.directory, withAWS: args.withAWS)
}
}
}
Expand Down Expand Up @@ -870,14 +870,15 @@ def tarAndUploadArtifacts(Map args = [:]) {
* This method executes a closure with credentials for cloud test
* environments.
*/
def withCloudTestEnv(Closure body) {
def withCloudTestEnv(Map args = [:], Closure body) {
def maskedVars = []
def testTags = "${env.TEST_TAGS}"

// Allow AWS credentials when the build was configured to do so with:
// - the cloudtests build parameters
// - the aws github label
if (params.allCloudTests || params.awsCloudTests || matchesPrLabel(label: 'aws')) {
// - forced with the cloud argument aws github label
if (params.allCloudTests || params.awsCloudTests || matchesPrLabel(label: 'aws') || args.get('withAWS', false)) {
testTags = "${testTags},aws"
def aws = getVaultSecret(secret: "${AWS_ACCOUNT_SECRET}").data
if (!aws.containsKey('access_key')) {
Expand All @@ -891,6 +892,7 @@ def withCloudTestEnv(Closure body) {
[var: "AWS_ACCESS_KEY_ID", password: aws.access_key],
[var: "AWS_SECRET_ACCESS_KEY", password: aws.secret_key],
])
log(level: 'INFO', text: 'withCloudTestEnv: it has been configured to run in AWS.')
}

withEnv([
Expand All @@ -916,7 +918,7 @@ def startCloudTestEnv(Map args = [:]) {
String name = normalise(args.name)
def dirs = args.get('dirs',[])
stage("${name}-prepare-cloud-env"){
withCloudTestEnv() {
withCloudTestEnv(args) {
withBeatsEnv(archive: false, withModule: false) {
try {
dirs?.each { folder ->
Expand Down Expand Up @@ -959,7 +961,7 @@ def terraformCleanup(Map args = [:]) {
String name = normalise(args.name)
String directory = args.dir
stage("${name}-tear-down-cloud-env"){
withCloudTestEnv() {
withCloudTestEnv(args) {
withBeatsEnv(archive: false, withModule: false) {
unstash("terraform-${name}")
retryWithSleep(retries: 2, seconds: 5, backoff: true) {
Expand Down Expand Up @@ -1084,6 +1086,7 @@ class RunCommand extends co.elastic.beats.BeatsFunction {
public run(Map args = [:]){
steps.stageStatusCache(args){
def withModule = args.content.get('withModule', false)
def withAWS = args.content.get('withAWS', false)
//
// What's the retry policy for fighting the flakiness:
// 1) Lint/Packaging/Cloud/k8sTest stages don't retry, since their failures are normally legitim
Expand Down Expand Up @@ -1142,7 +1145,7 @@ class RunCommand extends co.elastic.beats.BeatsFunction {
steps.k8sTest(context: args.context, versions: args.content.k8sTest.split(','), label: args.label, id: args.id)
}
if(args?.content?.containsKey('cloud')) {
steps.cloud(context: args.context, command: args.content.cloud, directory: args.project, label: args.label, withModule: withModule, dirs: args.content.dirs, id: args.id)
steps.cloud(context: args.context, command: args.content.cloud, directory: args.project, label: args.label, withModule: withModule, dirs: args.content.dirs, id: args.id, withAWS: withAWS)
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions x-pack/filebeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ stages:
labels:
- "aws"
stage: extended
cloudAWS:
cloud: "mage build test"
withAWS: true ## Enable the tests to run in AWS
withModule: true ## run the ITs only if the changeset affects a specific module.
dirs: ## run the cloud tests for the given modules.
- "x-pack/filebeat/input/awss3/_meta/terraform"
when: ## Override the top-level when.
changeset: ## when PR contains any of those entries in the changeset
- "^x-pack/filebeat/input/awss3/.*"
- "^x-pack/filebeat/module/aws/.*"
- "^x-pack/filebeat/input/awscloudwatch/.*"
- "^x-pack/filebeat/Jenkinsfile.yml"
- "^x-pack/libbeat/common/aws/.*"
stage: extended
#windows-7-32: See https://github.com/elastic/beats/issues/22315
# mage: "mage build unitTest"
# platforms: ## override default labels in this specific stage.
Expand Down
12 changes: 12 additions & 0 deletions x-pack/metricbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ stages:
labels:
- "aws"
stage: extended
cloudAWS:
cloud: "mage build test"
withAWS: true ## Enable the tests to run in AWS
withModule: true ## run the ITs only if the changeset affects a specific module.
dirs: ## run the cloud tests for the given modules.
- "x-pack/metricbeat/module/aws"
when: ## Override the top-level when.
changeset: ## when PR contains any of those entries in the changeset
- "^x-pack/metricbeat/module/aws/.*"
- "^x-pack/metricbeat/Jenkinsfile.yml"
- "^x-pack/libbeat/common/aws/.*"
stage: extended
macos:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down

0 comments on commit 5f2e365

Please sign in to comment.