From 850090bdccba6adc90b9b25c00189dd4ee0936fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 20 Apr 2021 13:20:13 +0200 Subject: [PATCH] fix: wrong interpolation (#1042) | chore: add debug traces for the webhook payload (#1043) | chore: add debug info for the payload (#1044) | fix: typo in parameters (#1045) | fix: incorrect variable name (#1046) | fix: do not use GT_REPO va (#1059) * fix: wrong interpolation (#1042) * chore: add debug traces for the webhook payload (#1043) * chore: add debug info for the payload (#1044) * fix: do not use variable names as variable prefix * chore: print payload * fix: perform another API call to fetch PR data We need a second API request, as the issue_comment API does not retrieve data about the pull request. See https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment * fix: typo in parameters (#1045) * fix: incorrect variable name (#1046) * fix: do not use GT_REPO variable, use fixed repo name instead (#1049) * fix: do not use GT_REPO variable, use fixed repo name Because the repo is always Kibana, let's use it * chore: remove unused echo --- .ci/e2eKibana.groovy | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/.ci/e2eKibana.groovy b/.ci/e2eKibana.groovy index 9ac52601ed..33777a0cd9 100644 --- a/.ci/e2eKibana.groovy +++ b/.ci/e2eKibana.groovy @@ -7,6 +7,8 @@ pipeline { environment { REPO = 'kibana' BASE_DIR = "src/github.com/elastic/${env.REPO}" + ELASTIC_REPO = "elastic/${env.REPO}" + GITHUB_APP_SECRET = 'secret/observability-team/ci/github-app' GITHUB_CHECK_E2E_TESTS_NAME = 'E2E Tests' PIPELINE_LOG_LEVEL = "INFO" } @@ -25,16 +27,14 @@ pipeline { GenericTrigger( genericVariables: [ [key: 'GT_REPO', value: '$.repository.full_name'], - [key: 'GT_BASE_REF', value: '$.pull_request.base.ref'], [key: 'GT_PR', value: '$.issue.number'], - [key: 'GT_PR_HEAD_SHA', value: '$.pull_request.head.sha'], [key: 'GT_BODY', value: '$.comment.body'], [key: 'GT_COMMENT_ID', value: '$.comment.id'] ], genericHeaderVariables: [ [key: 'x-github-event', regexpFilter: 'comment'] ], - causeString: 'Triggered on comment: $GT_BODY', + causeString: 'Triggered on #$GT_PR via comment: $GT_BODY', printContributedVariables: false, printPostContent: false, silentResponse: true, @@ -69,36 +69,47 @@ def checkPermissions(){ error("Only PRs from Elasticians can be tested with Fleet E2E tests") } - if(!hasCommentAuthorWritePermissions(repoName: 'elastic/kibana', commentId: env.GT_COMMENT_ID)){ + if(!hasCommentAuthorWritePermissions(repoName: "${env.ELASTIC_REPO}", commentId: env.GT_COMMENT_ID)){ error("Only Elasticians can trigger Fleet E2E tests") } } } def getBranch(){ + return "PR/" + getID() +} + +def getID(){ if(env.GT_PR){ - return "PR/${env.GT_PR}" + return "${env.GT_PR}" } - return "PR/${params.kibana_pr}" + return "${params.kibana_pr}" } -def getDockerTag(){ +def runE2ETests(String suite) { + // we need a second API request, as the issue_comment API does not retrieve data about the pull request + // See https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment + def prID = getID() + def token = githubAppToken(secret: "${env.GITHUB_APP_SECRET}") + + def pullRequest = githubApiCall(token: token, url: "https://api.github.com/repos/${env.ELASTIC_REPO}/pulls/${prID}") + def baseRef = pullRequest?.base?.ref + def headSha = pullRequest?.head?.sha + + // we are going to use the 'pr12345' tag as default + def dockerTag = "pr${params.kibana_pr}" if(env.GT_PR){ - return "${env.GT_PR_HEAD_SHA}" + // it's a PR: we are going to use its head SHA as tag + dockerTag = headSha } - // we are going to use the 'pr12345' tag - return "pr${params.kibana_pr}" -} - -def runE2ETests(String suite) { - log(level: 'DEBUG', text: "Triggering '${suite}' E2E tests for PR-${env.GT_PR}.") + log(level: 'DEBUG', text: "Triggering '${suite}' E2E tests for PR-${prID} using '${dockerTag}' as Docker tag") // Kibana's maintenance branches follow the 7.11, 7.12 schema. - def branchName = "${env.GT_BASE_REF}" - if (${env.GT_BASE_REF} != "master") { - branchName = "${env.GT_BASE_REF}.x" + def branchName = "${baseRef}" + if (branchName != "master") { + branchName += ".x" } def e2eTestsPipeline = "e2e-tests/e2e-testing-mbp/${branchName}" @@ -110,7 +121,7 @@ def runE2ETests(String suite) { string(name: 'runTestsSuites', value: suite), string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_E2E_TESTS_NAME), string(name: 'GITHUB_CHECK_REPO', value: env.REPO), - string(name: 'KIBANA_VERSION', value: getDockerTag()), + string(name: 'KIBANA_VERSION', value: dockerTag), ] build(job: "${e2eTestsPipeline}",