Skip to content

Commit 064493d

Browse files
v1vmergify-bot
authored andcommitted
CI: enable AWS cloud testing on a PR basis if changes in certain files (#29047)
(cherry picked from commit 3dc0afb)
1 parent d490c1c commit 064493d

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

Jenkinsfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ def generateStages(Map args = [:]) {
277277
def cloud(Map args = [:]) {
278278
withGithubNotify(context: args.context) {
279279
withNode(labels: args.label, forceWorkspace: true){
280-
startCloudTestEnv(name: args.directory, dirs: args.dirs)
280+
startCloudTestEnv(name: args.directory, dirs: args.dirs, withAWS: args.withAWS)
281281
}
282-
withCloudTestEnv() {
282+
withCloudTestEnv(args) {
283283
try {
284284
target(context: args.context, command: args.command, directory: args.directory, label: args.label, withModule: args.withModule, isMage: true, id: args.id)
285285
} finally {
286-
terraformCleanup(name: args.directory, dir: args.directory)
286+
terraformCleanup(name: args.directory, dir: args.directory, withAWS: args.withAWS)
287287
}
288288
}
289289
}
@@ -851,14 +851,15 @@ def tarAndUploadArtifacts(Map args = [:]) {
851851
* This method executes a closure with credentials for cloud test
852852
* environments.
853853
*/
854-
def withCloudTestEnv(Closure body) {
854+
def withCloudTestEnv(Map args = [:], Closure body) {
855855
def maskedVars = []
856856
def testTags = "${env.TEST_TAGS}"
857857

858858
// Allow AWS credentials when the build was configured to do so with:
859859
// - the cloudtests build parameters
860860
// - the aws github label
861-
if (params.allCloudTests || params.awsCloudTests || matchesPrLabel(label: 'aws')) {
861+
// - forced with the cloud argument aws github label
862+
if (params.allCloudTests || params.awsCloudTests || matchesPrLabel(label: 'aws') || args.get('withAWS', false)) {
862863
testTags = "${testTags},aws"
863864
def aws = getVaultSecret(secret: "${AWS_ACCOUNT_SECRET}").data
864865
if (!aws.containsKey('access_key')) {
@@ -872,6 +873,7 @@ def withCloudTestEnv(Closure body) {
872873
[var: "AWS_ACCESS_KEY_ID", password: aws.access_key],
873874
[var: "AWS_SECRET_ACCESS_KEY", password: aws.secret_key],
874875
])
876+
log(level: 'INFO', text: 'withCloudTestEnv: it has been configured to run in AWS.')
875877
}
876878

877879
withEnv([
@@ -897,7 +899,7 @@ def startCloudTestEnv(Map args = [:]) {
897899
String name = normalise(args.name)
898900
def dirs = args.get('dirs',[])
899901
stage("${name}-prepare-cloud-env"){
900-
withCloudTestEnv() {
902+
withCloudTestEnv(args) {
901903
withBeatsEnv(archive: false, withModule: false) {
902904
try {
903905
dirs?.each { folder ->
@@ -940,7 +942,7 @@ def terraformCleanup(Map args = [:]) {
940942
String name = normalise(args.name)
941943
String directory = args.dir
942944
stage("${name}-tear-down-cloud-env"){
943-
withCloudTestEnv() {
945+
withCloudTestEnv(args) {
944946
withBeatsEnv(archive: false, withModule: false) {
945947
unstash("terraform-${name}")
946948
retryWithSleep(retries: 2, seconds: 5, backoff: true) {
@@ -1065,6 +1067,7 @@ class RunCommand extends co.elastic.beats.BeatsFunction {
10651067
public run(Map args = [:]){
10661068
steps.stageStatusCache(args){
10671069
def withModule = args.content.get('withModule', false)
1070+
def withAWS = args.content.get('withAWS', false)
10681071
//
10691072
// What's the retry policy for fighting the flakiness:
10701073
// 1) Lint/Packaging/Cloud/k8sTest stages don't retry, since their failures are normally legitim
@@ -1123,7 +1126,7 @@ class RunCommand extends co.elastic.beats.BeatsFunction {
11231126
steps.k8sTest(context: args.context, versions: args.content.k8sTest.split(','), label: args.label, id: args.id)
11241127
}
11251128
if(args?.content?.containsKey('cloud')) {
1126-
steps.cloud(context: args.context, command: args.content.cloud, directory: args.project, label: args.label, withModule: withModule, dirs: args.content.dirs, id: args.id)
1129+
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)
11271130
}
11281131
}
11291132
}

x-pack/filebeat/Jenkinsfile.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ stages:
113113
labels:
114114
- "aws"
115115
stage: extended
116+
cloudAWS:
117+
cloud: "mage build test"
118+
withAWS: true ## Enable the tests to run in AWS
119+
withModule: true ## run the ITs only if the changeset affects a specific module.
120+
dirs: ## run the cloud tests for the given modules.
121+
- "x-pack/filebeat/input/awss3/_meta/terraform"
122+
when: ## Override the top-level when.
123+
changeset: ## when PR contains any of those entries in the changeset
124+
- "^x-pack/filebeat/input/awss3/.*"
125+
- "^x-pack/filebeat/module/aws/.*"
126+
- "^x-pack/filebeat/input/awscloudwatch/.*"
127+
- "^x-pack/filebeat/Jenkinsfile.yml"
128+
- "^x-pack/libbeat/common/aws/.*"
129+
stage: extended
116130
#windows-7-32: See https://github.com/elastic/beats/issues/22315
117131
# mage: "mage build unitTest"
118132
# platforms: ## override default labels in this specific stage.

x-pack/metricbeat/Jenkinsfile.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ stages:
4545
labels:
4646
- "aws"
4747
stage: extended
48+
cloudAWS:
49+
cloud: "mage build test"
50+
withAWS: true ## Enable the tests to run in AWS
51+
withModule: true ## run the ITs only if the changeset affects a specific module.
52+
dirs: ## run the cloud tests for the given modules.
53+
- "x-pack/metricbeat/module/aws"
54+
when: ## Override the top-level when.
55+
changeset: ## when PR contains any of those entries in the changeset
56+
- "^x-pack/metricbeat/module/aws/.*"
57+
- "^x-pack/metricbeat/Jenkinsfile.yml"
58+
- "^x-pack/libbeat/common/aws/.*"
59+
stage: extended
4860
macos:
4961
mage: "mage build unitTest"
5062
platforms: ## override default label in this specific stage.

0 commit comments

Comments
 (0)