From 6c8935e747e6e0bf748bd5888806979ca63c2aad Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Thu, 16 Feb 2023 18:00:57 +0100 Subject: [PATCH 1/4] Test existence of commit --- .ci/Jenkinsfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index de7de19137..173ec488cf 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -23,6 +23,7 @@ pipeline { JOB_GCS_EXT_CREDENTIALS = 'fleet-ci-gcs-plugin-file-credentials' ELASTIC_PACKAGE_GCP_SECRET = 'secret/observability-team/ci/service-account/elastic-package-gcp' ELASTIC_OBSERVABILITY_PROJECT_ID = 'elastic-observability' + BUILDKITE_MERGE_COMMIT = "79ee1738578deac17f8f5caf8d925db6244ab6df" } options { timeout(time: 1, unit: 'HOURS') @@ -55,6 +56,30 @@ pipeline { /** Check the source code. */ + stage('Check it contains Buildkite pipeline') { + steps { + cleanup() + dir("${BASE_DIR}"){ + githubEnv() + gitCmd(cmd: 'fetch', args: '+refs/heads/*:refs/remotes/origin/*') + sh(label: 'Check', script: ''' + echo "Current commit: ${GIT_COMMIT}" + echo "Current base commit: ${GIT_BASE_COMMIT}" + git fetch + git branch -a --contains "${GIT_BASE_COMMIT}" + echo "Current branch: ${GIT_BRANCH} - ${BRANCH_NAME}" + git branch -a "${GIT_BRANCH}" --contains "${BUILDKITE_MERGE_COMMIT}" + git branch -a --contains "${BUILDKITE_MERGE_COMMIT}" + git rev-parse --abbrev-ref HEAD + + git log --format=%H "${GIT_BASE_COMMIT}" | grep "${BUILDKITE_MERGE_COMMIT}" + ''') + } + } + } + /** + Check the source code. + */ stage('Check static') { steps { cleanup() From 5cb608345f5c14056404d11d3f3f8f4732bd4872 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Thu, 16 Feb 2023 18:12:36 +0100 Subject: [PATCH 2/4] Add message --- .ci/Jenkinsfile | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 173ec488cf..450b8f8a66 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -60,20 +60,25 @@ pipeline { steps { cleanup() dir("${BASE_DIR}"){ - githubEnv() - gitCmd(cmd: 'fetch', args: '+refs/heads/*:refs/remotes/origin/*') - sh(label: 'Check', script: ''' - echo "Current commit: ${GIT_COMMIT}" - echo "Current base commit: ${GIT_BASE_COMMIT}" - git fetch - git branch -a --contains "${GIT_BASE_COMMIT}" - echo "Current branch: ${GIT_BRANCH} - ${BRANCH_NAME}" - git branch -a "${GIT_BRANCH}" --contains "${BUILDKITE_MERGE_COMMIT}" - git branch -a --contains "${BUILDKITE_MERGE_COMMIT}" - git rev-parse --abbrev-ref HEAD + script { + githubEnv() + gitCmd(cmd: 'fetch', args: '+refs/heads/*:refs/remotes/origin/*') + r = sh(label: 'Check', returnStatus: true, script: ''' + echo "Current commit: ${GIT_COMMIT}" + echo "Current base commit: ${GIT_BASE_COMMIT}" + git branch -a --contains "${GIT_BASE_COMMIT}" + echo "Current branch: ${GIT_BRANCH} - ${BRANCH_NAME}" + git branch -a "${GIT_BRANCH}" --contains "${BUILDKITE_MERGE_COMMIT}" + git branch -a --contains "${BUILDKITE_MERGE_COMMIT}" + git rev-parse --abbrev-ref HEAD - git log --format=%H "${GIT_BASE_COMMIT}" | grep "${BUILDKITE_MERGE_COMMIT}" - ''') + git log --format=%H "${GIT_BASE_COMMIT}" | grep "${BUILDKITE_MERGE_COMMIT}" + ''') + if (r == 0) { + echo("You should update your branch to include latest buildkite pipelines") + sh(label: 'Exit', script: 'exit 1') + } + } } } } From f1b0e8cbd12b96ed3fe3c9dc7eb7cde5bb244a49 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Thu, 16 Feb 2023 18:17:14 +0100 Subject: [PATCH 3/4] Check for error --- .ci/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 450b8f8a66..2982b219f3 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -74,7 +74,7 @@ pipeline { git log --format=%H "${GIT_BASE_COMMIT}" | grep "${BUILDKITE_MERGE_COMMIT}" ''') - if (r == 0) { + if (r != 0) { echo("You should update your branch to include latest buildkite pipelines") sh(label: 'Exit', script: 'exit 1') } From 36c0dbd9473bd4aafa27a445700cab8d8beca755 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Thu, 16 Feb 2023 18:24:11 +0100 Subject: [PATCH 4/4] Check just log --- .ci/Jenkinsfile | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index 2982b219f3..8103f87e0c 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -62,16 +62,8 @@ pipeline { dir("${BASE_DIR}"){ script { githubEnv() - gitCmd(cmd: 'fetch', args: '+refs/heads/*:refs/remotes/origin/*') r = sh(label: 'Check', returnStatus: true, script: ''' - echo "Current commit: ${GIT_COMMIT}" - echo "Current base commit: ${GIT_BASE_COMMIT}" - git branch -a --contains "${GIT_BASE_COMMIT}" - echo "Current branch: ${GIT_BRANCH} - ${BRANCH_NAME}" - git branch -a "${GIT_BRANCH}" --contains "${BUILDKITE_MERGE_COMMIT}" - git branch -a --contains "${BUILDKITE_MERGE_COMMIT}" - git rev-parse --abbrev-ref HEAD - + echo "Base commit: ${GIT_BASE_COMMIT}" git log --format=%H "${GIT_BASE_COMMIT}" | grep "${BUILDKITE_MERGE_COMMIT}" ''') if (r != 0) {