Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pipeline {
quietPeriod(10)
}
triggers {
issueCommentTrigger("${obltGitHubComments()}")
issueCommentTrigger("(${obltGitHubComments()}|^/test all)")
}
parameters {
string(name: 'stackVersion', defaultValue: '', description: 'Version of the stack to use for testing.')
Expand All @@ -41,6 +41,10 @@ pipeline {
deleteDir()
gitCheckout(basedir: "${BASE_DIR}")
stashV2(name: 'source', bucket: "${JOB_GCS_BUCKET}", credentialsId: "${JOB_GCS_CREDENTIALS}")
dir("${BASE_DIR}"){
// TODO: '^.ci/Jenkinsfile' too
setEnvVar('COMMON_CHANGES', isGitRegionMatch(patterns: [ '(^go.*|.go-version)' ], shouldMatchAll: false).toString())
}
}
}
stage('Check Go sources') {
Expand All @@ -61,7 +65,7 @@ pipeline {
// Include hack to skip temporary files with "@tmp" suffix.
// For reference: https://issues.jenkins.io/browse/JENKINS-52750
findFiles()?.findAll{ !it.name.endsWith('@tmp') }?.collect{ it.name }?.sort()?.each {
if (isPrAffected(it)) {
if (isPackageEnabled(it)) {
integrations[it] = {
withNode(labels: 'ubuntu-20 && immutable', sleepMin: 10, sleepMax: 100) {
stage("${it}: check") {
Expand Down Expand Up @@ -146,7 +150,30 @@ def checkGitDiff() {
}
}

def isPrAffected(integrationName) {
/**
* Helper function to validate if the given integration is enabled
* If it's a branch, a daily build, a GitHub comment or the changeset
* contains the integration or some common changes then it will be true,
* otherwise false.
*/
def isPackageEnabled(integrationName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I fully understand the intention here. Which part of the helper is the "smart" one (as in the PR title)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart was just a name, easy to change.

I tried to explain what I did and why in the PR description, but in a nutshell, if I understood correctly, the packages should be triggered based on the below conditions:

  1. when a daily build as requested in Fix: don't include 8.x packages in stack 7.x jobs #2334 . I used daily to be aligned with the reason described in the PR.
  2. On a PR only if there are changes in the specific package, as done in Run "check" and "test" only for affected packages in PRs #474
  3. For branches done in Run "check" and "test" only for affected packages in PRs #474 (since only main is available, then env.branch_name=='main' instead(so I'll amend this)
  4. Allow to change the PR behaviour with a GitHub command, that's handy as 2) won't allow to do so.
  5. On a PR if changes in the some common shared files (.ci/Jenkinsfile, go.mod...), this is handy to test the pipeline itself and avoid 2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re 5:

What about dependabot updates? We need to check all integrations then. Imagine that there is a bug in elastic-package, and ~3/100 integrations may catch it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about dependabot updates?

Since it changes go.mod then it triggers all the integrations. So that's also covered

if (isBranch()) {
log(level: 'INFO', text: "[${integrationName}] is affected: running on ${BRANCH_NAME} branch.")
return true
}
if (isDailyEnabled(integrationName)) {
return true
}
if (isPrAffected(integrationName)) {
return true
}
return env.GITHUB_COMMENT?.contains('all') || env.COMMON_CHANGES == 'true'
}

def isDailyEnabled(integrationName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar question here, why do we need a separate function for Daily?

if (isPR()) {
return false
}
def manifest = readYaml(file: "${integrationName}/manifest.yml")

// Packages supported in Kibana >= 8.0.0, shouldn't be included in daily tests of the stack 7.x
Expand All @@ -163,10 +190,11 @@ def isPrAffected(integrationName) {
}
}
}
}

if (env.BRANCH_NAME == "main") {
echo "[${integrationName}] PR is affected: running on main branch"
return true
def isPrAffected(integrationName) {
if (!isPR()) {
return false
}

// Source: https://github.com/elastic/apm-pipeline-library/blob/721115cf0fdb2b5a4e1cb6a576bfbb7035d14485/vars/getGitMatchingGroup.groovy#L40-L41
Expand Down