From 3ad0b696270753bf3ed7a0a2f52380c9c7475eed Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 9 Feb 2022 14:53:14 +0000 Subject: [PATCH] ci: workflow on PR, merges and nightlies (#23) --- .ci/Jenkinsfile | 45 +++++++++++++- .ci/jobs/elastic-agent-schedule-daily.yml | 26 ++++++++ .ci/schedule-daily.groovy | 73 +++++++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 .ci/jobs/elastic-agent-schedule-daily.yml create mode 100644 .ci/schedule-daily.groovy diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 93a09d3209..51fba1cbc4 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -23,7 +23,16 @@ pipeline { quietPeriod(10) } triggers { - issueCommentTrigger("${obltGitHubComments()}") + issueCommentTrigger("(${obltGitHubComments()}|^run ((integration|end-to-end) tests|package)") + } + parameters { + // disabled by default, but required for merge, there are two GH checks: + // opt-in with 'ci:integration' + booleanParam(name: 'integration_tests_ci', defaultValue: false, description: 'Enable Integration tests') + + // disabled by default, but required for merge: + // opt-in with 'ci:end-to-end' tag on PR + booleanParam(name: 'end_to_end_tests_ci', defaultValue: false, description: 'Enable End-to-End tests') } stages { stage('Checkout') { @@ -94,6 +103,14 @@ pipeline { } } stage('Package') { + when { + beforeAgent true + anyOf { + expression { return env.GITHUB_COMMENT?.contains('package') } + expression { matchesPrLabel(label: 'ci:package') } + not { changeRequest() } + } + } failFast false matrix { agent {label "${PLATFORM}"} @@ -124,6 +141,32 @@ pipeline { } } } + stage('e2e tests') { + when { + beforeAgent true + anyOf { + expression { return params.end_to_end_tests_ci } + expression { return env.GITHUB_COMMENT?.contains('e2e tests') } + expression { matchesPrLabel(label: 'ci:end-to-end') } + } + } + steps { + echo 'TBD' + } + } + stage('Integration tests') { + when { + beforeAgent true + anyOf { + expression { return params.integration_tests_ci } + expression { return env.GITHUB_COMMENT?.contains('integration tests') } + expression { matchesPrLabel(label: 'ci:integration') } + } + } + steps { + echo 'TBD' + } + } } post { cleanup { diff --git a/.ci/jobs/elastic-agent-schedule-daily.yml b/.ci/jobs/elastic-agent-schedule-daily.yml new file mode 100644 index 0000000000..7408f86fa7 --- /dev/null +++ b/.ci/jobs/elastic-agent-schedule-daily.yml @@ -0,0 +1,26 @@ +--- +- job: + name: "elastic-agent/elastic-agent-schedule-daily" + display-name: Jobs scheduled daily (weekdays) + description: Jobs scheduled daily (weekdays) + view: Beats + project-type: pipeline + parameters: + - string: + name: branch_specifier + default: main + description: the Git branch specifier to build + pipeline-scm: + script-path: .ci/schedule-daily.groovy + scm: + - git: + url: git@github.com:elastic/elastic-agent-poc.git + refspec: +refs/heads/*:refs/remotes/origin/* + wipe-workspace: 'True' + name: origin + shallow-clone: true + credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba + branches: + - $branch_specifier + triggers: + - timed: 'H H(2-3) * * 1-5' diff --git a/.ci/schedule-daily.groovy b/.ci/schedule-daily.groovy new file mode 100644 index 0000000000..0c74fbe476 --- /dev/null +++ b/.ci/schedule-daily.groovy @@ -0,0 +1,73 @@ +@Library('apm@current') _ + +pipeline { + agent none + environment { + NOTIFY_TO = credentials('notify-to') + PIPELINE_LOG_LEVEL = 'INFO' + } + options { + timeout(time: 1, unit: 'HOURS') + buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20')) + timestamps() + ansiColor('xterm') + disableResume() + durabilityHint('PERFORMANCE_OPTIMIZED') + } + triggers { + cron('H H(2-3) * * 1-5') + } + stages { + stage('Nighly beats builds') { + steps { + runBuilds(quietPeriodFactor: 2000, branches: ['main', '8.', '7.', '7.']) + } + } + } + post { + cleanup { + notifyBuildResult(prComment: false) + } + } +} + +def runBuilds(Map args = [:]) { + def branches = [] + // Expand macros and filter duplicated matches. + args.branches.each { branch -> + def branchName = getBranchName(branch) + if (!branches.contains(branchName)) { + branches << branchName + } + } + + def quietPeriod = 0 + branches.each { branch -> + build(quietPeriod: quietPeriod, + job: "elastic-agent/elastic-agent-poc-mbp/${branch}", + parameters: [ + booleanParam(name: 'integration_tests_ci', value: true), + booleanParam(name: 'end_to_end_tests_ci', value: true) + ], + wait: false, propagate: false) + // Increate the quiet period for the next iteration + quietPeriod += args.quietPeriodFactor + } +} + +def getBranchName(branch) { + // special macro to look for the latest minor version + if (branch.contains('8.')) { + return bumpUtils.getMajorMinor(bumpUtils.getCurrentMinorReleaseFor8()) + } + if (branch.contains('8.')) { + return bumpUtils.getMajorMinor(bumpUtils.getNextMinorReleaseFor8()) + } + if (branch.contains('7.')) { + return bumpUtils.getMajorMinor(bumpUtils.getCurrentMinorReleaseFor7()) + } + if (branch.contains('7.')) { + return bumpUtils.getMajorMinor(bumpUtils.getNextMinorReleaseFor7()) + } + return branch +}