Skip to content

Commit 67e19ee

Browse files
committed
Only run xpack siem cypress in PRs when there are siem changes (#60661)
1 parent 0ef9835 commit 67e19ee

3 files changed

Lines changed: 72 additions & 3 deletions

File tree

Jenkinsfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ kibanaPipeline(timeoutMinutes: 135, checkPrChanges: true) {
4040
'xpack-ciGroup9': kibanaPipeline.xpackCiGroupProcess(9),
4141
'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10),
4242
'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'),
43-
'xpack-siemCypress': kibanaPipeline.functionalTestProcess('xpack-siemCypress', './test/scripts/jenkins_siem_cypress.sh'),
43+
'xpack-siemCypress': { processNumber ->
44+
whenChanged(['x-pack/legacy/plugins/siem/', 'x-pack/test/siem_cypress/']) {
45+
kibanaPipeline.functionalTestProcess('xpack-siemCypress', './test/scripts/jenkins_siem_cypress.sh')(processNumber)
46+
}
47+
},
48+
4449
// 'xpack-visualRegression': kibanaPipeline.functionalTestProcess('xpack-visualRegression', './test/scripts/jenkins_xpack_visual_regression.sh'),
4550
]),
4651
])

vars/prChanges.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import groovy.transform.Field
2+
3+
public static @Field PR_CHANGES_CACHE = null
14

25
def getSkippablePaths() {
36
return [
@@ -36,9 +39,13 @@ def areChangesSkippable() {
3639
}
3740

3841
def getChanges() {
39-
withGithubCredentials {
40-
return githubPrs.getChanges(env.ghprbPullId)
42+
if (!PR_CHANGES_CACHE && env.ghprbPullId) {
43+
withGithubCredentials {
44+
PR_CHANGES_CACHE = githubPrs.getChanges(env.ghprbPullId)
45+
}
4146
}
47+
48+
return PR_CHANGES_CACHE
4249
}
4350

4451
def getChangedFiles() {

vars/whenChanged.groovy

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
whenChanged('some/path') { yourCode() } can be used to execute pipeline code in PRs only when changes are detected on paths that you specify.
3+
The specified code blocks will also always be executed during the non-PR jobs for tracked branches.
4+
5+
You have the option of passing in path prefixes, or regexes. Single or multiple.
6+
Path specifications are NOT globby, they are only prefixes.
7+
Specifying multiple will treat them as ORs.
8+
9+
Example Usages:
10+
whenChanged('a/path/prefix/') { someCode() }
11+
whenChanged(startsWith: 'a/path/prefix/') { someCode() } // Same as above
12+
whenChanged(['prefix1/', 'prefix2/']) { someCode() }
13+
whenChanged(regex: /\.test\.js$/) { someCode() }
14+
whenChanged(regex: [/abc/, /xyz/]) { someCode() }
15+
*/
16+
17+
def call(String startsWithString, Closure closure) {
18+
return whenChanged([ startsWith: startsWithString ], closure)
19+
}
20+
21+
def call(List<String> startsWithStrings, Closure closure) {
22+
return whenChanged([ startsWith: startsWithStrings ], closure)
23+
}
24+
25+
def call(Map params, Closure closure) {
26+
if (!githubPr.isPr()) {
27+
return closure()
28+
}
29+
30+
def files = prChanges.getChangedFiles()
31+
def hasMatch = false
32+
33+
if (params.regex) {
34+
params.regex = [] + params.regex
35+
print "Checking PR for changes that match: ${params.regex.join(', ')}"
36+
hasMatch = !!files.find { file ->
37+
params.regex.find { regex -> file =~ regex }
38+
}
39+
}
40+
41+
if (!hasMatch && params.startsWith) {
42+
params.startsWith = [] + params.startsWith
43+
print "Checking PR for changes that start with: ${params.startsWith.join(', ')}"
44+
hasMatch = !!files.find { file ->
45+
params.startsWith.find { str -> file.startsWith(str) }
46+
}
47+
}
48+
49+
if (hasMatch) {
50+
print "Changes found, executing pipeline."
51+
closure()
52+
} else {
53+
print "No changes found, skipping."
54+
}
55+
}
56+
57+
return this

0 commit comments

Comments
 (0)