mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
Skip CI based on changes in PR (#59939)
This commit is contained in:
parent
1ede10ccbc
commit
8d19fb05a1
5 changed files with 72 additions and 10 deletions
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
|
@ -3,7 +3,7 @@
|
||||||
library 'kibana-pipeline-library'
|
library 'kibana-pipeline-library'
|
||||||
kibanaLibrary.load()
|
kibanaLibrary.load()
|
||||||
|
|
||||||
kibanaPipeline(timeoutMinutes: 135) {
|
kibanaPipeline(timeoutMinutes: 135, checkPrChanges: true) {
|
||||||
githubPr.withDefaultPrComments {
|
githubPr.withDefaultPrComments {
|
||||||
catchError {
|
catchError {
|
||||||
retryable.enable()
|
retryable.enable()
|
||||||
|
|
|
@ -194,14 +194,6 @@ def getNextCommentMessage(previousCommentInfo = [:]) {
|
||||||
.join("\n\n")
|
.join("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
def withGithubCredentials(closure) {
|
|
||||||
withCredentials([
|
|
||||||
string(credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7', variable: 'GITHUB_TOKEN'),
|
|
||||||
]) {
|
|
||||||
closure()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def postComment(message) {
|
def postComment(message) {
|
||||||
if (!isPr()) {
|
if (!isPr()) {
|
||||||
error "Trying to post a GitHub PR comment on a non-PR or non-elastic PR build"
|
error "Trying to post a GitHub PR comment on a non-PR or non-elastic PR build"
|
||||||
|
|
|
@ -202,12 +202,20 @@ def runErrorReporter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
def call(Map params = [:], Closure closure) {
|
def call(Map params = [:], Closure closure) {
|
||||||
def config = [timeoutMinutes: 135] + params
|
def config = [timeoutMinutes: 135, checkPrChanges: false] + params
|
||||||
|
|
||||||
stage("Kibana Pipeline") {
|
stage("Kibana Pipeline") {
|
||||||
timeout(time: config.timeoutMinutes, unit: 'MINUTES') {
|
timeout(time: config.timeoutMinutes, unit: 'MINUTES') {
|
||||||
timestamps {
|
timestamps {
|
||||||
ansiColor('xterm') {
|
ansiColor('xterm') {
|
||||||
|
if (config.checkPrChanges && githubPr.isPr()) {
|
||||||
|
print "Checking PR for changes to determine if CI needs to be run..."
|
||||||
|
|
||||||
|
if (prChanges.areChangesSkippable()) {
|
||||||
|
print "No changes requiring CI found in PR, skipping."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
closure()
|
closure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,4 +223,5 @@ def call(Map params = [:], Closure closure) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
|
|
52
vars/prChanges.groovy
Normal file
52
vars/prChanges.groovy
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
def getSkippablePaths() {
|
||||||
|
return [
|
||||||
|
/^docs\//,
|
||||||
|
/^rfcs\//,
|
||||||
|
/^.ci\/.+\.yml$/,
|
||||||
|
/^\.github\//,
|
||||||
|
/\.md$/,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
def areChangesSkippable() {
|
||||||
|
if (!githubPr.isPr()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
def skippablePaths = getSkippablePaths()
|
||||||
|
def files = getChangedFiles()
|
||||||
|
|
||||||
|
// 3000 is the max files GH API will return
|
||||||
|
if (files.size() >= 3000) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
files = files.findAll { file ->
|
||||||
|
return !skippablePaths.find { regex -> file =~ regex}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files.size() < 1
|
||||||
|
} catch (ex) {
|
||||||
|
buildUtils.printStacktrace(ex)
|
||||||
|
print "Error while checking to see if CI is skippable based on changes. Will run CI."
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getChanges() {
|
||||||
|
withGithubCredentials {
|
||||||
|
return githubPrs.getChanges(env.ghprbPullId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getChangedFiles() {
|
||||||
|
def changes = getChanges()
|
||||||
|
def changedFiles = changes.collect { it.filename }
|
||||||
|
def renamedFiles = changes.collect { it.previousFilename }.findAll { it }
|
||||||
|
|
||||||
|
return changedFiles + renamedFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
9
vars/withGithubCredentials.groovy
Normal file
9
vars/withGithubCredentials.groovy
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
def call(closure) {
|
||||||
|
withCredentials([
|
||||||
|
string(credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7', variable: 'GITHUB_TOKEN'),
|
||||||
|
]) {
|
||||||
|
closure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
Loading…
Add table
Add a link
Reference in a new issue