From 274467d3303f89bf40493ab074fd84322f718579 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Fri, 15 Oct 2021 12:23:32 +0100 Subject: [PATCH] [CI] Add E2E for x-pack/elastic-agent (fleet) (#24112) (cherry picked from commit a2fde7209fcea8da38a63f1076a6077476145067) --- Jenkinsfile | 69 ++++++++++++++++++++-------- x-pack/elastic-agent/Jenkinsfile.yml | 4 +- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eb36447753c6..ccb0097481ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -511,15 +511,25 @@ def getBeatsName(baseDir) { return baseDir.replace('x-pack/', '') } +/** +* This method runs the end 2 end testing +*/ +def e2e(Map args = [:]) { + if (!args.e2e?.get('enabled', false)) { return } + if (args.e2e.get('entrypoint', '')?.trim()) { + e2e_with_entrypoint(args) + } else { + e2e_with_job(args) + } +} + /** * This method runs the end 2 end testing in the same worker where the packages have been * generated, this should help to speed up the things */ -def e2e(Map args = [:]) { - def enabled = args.e2e?.get('enabled', false) +def e2e_with_entrypoint(Map args = [:]) { def entrypoint = args.e2e?.get('entrypoint') def dockerLogFile = "docker_logs_${entrypoint}.log" - if (!enabled) { return } dir("${env.WORKSPACE}/src/github.com/elastic/e2e-testing") { // TBC with the target branch if running on a PR basis. git(branch: 'master', credentialsId: '2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken', url: 'https://github.com/elastic/e2e-testing.git') @@ -533,19 +543,46 @@ def e2e(Map args = [:]) { "LOG_LEVEL=TRACE"]) { def status = 0 filebeat(output: dockerLogFile){ - status = sh(script: ".ci/scripts/${entrypoint}", - label: "Run functional tests ${entrypoint}", - returnStatus: true) - } - junit(allowEmptyResults: true, keepLongStdio: true, testResults: "outputs/TEST-*.xml") - archiveArtifacts allowEmptyArchive: true, artifacts: "outputs/TEST-*.xml" - if (status != 0) { - error("ERROR: functional tests for ${args?.directory?.trim()} has failed. See the test report and ${dockerLogFile}.") + try { + sh(script: ".ci/scripts/${entrypoint}", label: "Run functional tests ${entrypoint}") + } finally { + junit(allowEmptyResults: true, keepLongStdio: true, testResults: "outputs/TEST-*.xml") + archiveArtifacts allowEmptyArchive: true, artifacts: "outputs/TEST-*.xml" + } } } } } +/** +* This method triggers the end 2 end testing job. +*/ +def e2e_with_job(Map args = [:]) { + def jobName = args.e2e?.get('job') + def testMatrixFile = args.e2e?.get('testMatrixFile', '') + def notifyContext = "e2e-${args.context}" + def e2eTestsPipeline = "${jobName}/${isPR() ? "${env.CHANGE_TARGET}" : "${env.JOB_BASE_NAME}"}" + + def parameters = [ + booleanParam(name: 'forceSkipGitChecks', value: true), + booleanParam(name: 'forceSkipPresubmit', value: true), + booleanParam(name: 'notifyOnGreenBuilds', value: !isPR()), + string(name: 'BEAT_VERSION', value: "${env.VERSION}-SNAPSHOT"), + string(name: 'testMatrixFile', value: testMatrixFile), + string(name: 'GITHUB_CHECK_NAME', value: notifyContext), + string(name: 'GITHUB_CHECK_REPO', value: env.REPO), + string(name: 'GITHUB_CHECK_SHA1', value: env.GIT_BASE_COMMIT), + ] + + build(job: "${e2eTestsPipeline}", + parameters: parameters, + propagate: false, + wait: false + ) + + githubNotify(context: "${notifyContext}", description: "${notifyContext} ...", status: 'PENDING', targetUrl: "${env.JENKINS_URL}search/?q=${e2eTestsPipeline.replaceAll('/','+')}") +} + /** * This method runs the given command supporting two kind of scenarios: * - make -C then the dir(location) is not required, aka by disaling isMage: false @@ -578,19 +615,15 @@ def target(Map args = [:]) { cmd(label: "${args.id?.trim() ? args.id : env.STAGE_NAME} - ${command}", script: "${command}") } } - // TODO: - // Packaging should happen only after the e2e? + // Publish packages should happen always to easily consume those artifacts if the + // e2e were triggered and failed. if (isPackaging) { publishPackages("${directory}") + pushCIDockerImages(beatsFolder: "${directory}", arch: dockerArch) } if(isE2E) { e2e(args) } - // TODO: - // push docker images should happen only after the e2e? - if (isPackaging) { - pushCIDockerImages(beatsFolder: "${directory}", arch: dockerArch) - } } } } diff --git a/x-pack/elastic-agent/Jenkinsfile.yml b/x-pack/elastic-agent/Jenkinsfile.yml index 5cf3a25e1719..23a5daf0a6f8 100644 --- a/x-pack/elastic-agent/Jenkinsfile.yml +++ b/x-pack/elastic-agent/Jenkinsfile.yml @@ -95,7 +95,9 @@ stages: packaging-linux: packaging-linux: "mage package" e2e: - enabled: false + enabled: true + job: 'e2e-tests/e2e-testing-mbp' + testMatrixFile: '.ci/.e2e-tests-for-elastic-agent.yaml' stage: packaging packaging-arm: packaging-arm: "mage package"