From 095fab029264c0c30c28212869f23ce50526c9a9 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: May 15 2019 23:44:29 +0000 Subject: Run the integration tests from the current branch Previously, the integration test pipeline was configured to always use the tests present on the master branch. When running the pre-merge pipeline for a PR, this would result in potentially out-dated tests being run. This change runs the tests from the current branch, allowing the code and the tests to evolve together. This also disables the default checkout of the master branch, which is unnecessary when calling checkout() from the pipeline. --- diff --git a/openshift/integration/koji/pipelines/templates/mbs-build.Jenkinsfile b/openshift/integration/koji/pipelines/templates/mbs-build.Jenkinsfile index fced9d7..a228c1a 100644 --- a/openshift/integration/koji/pipelines/templates/mbs-build.Jenkinsfile +++ b/openshift/integration/koji/pipelines/templates/mbs-build.Jenkinsfile @@ -42,6 +42,7 @@ pipeline { timestamps() timeout(time: 120, unit: 'MINUTES') buildDiscarder(logRotator(numToKeepStr: '10')) + skipDefaultCheckout() } environment { PIPELINE_NAMESPACE = readFile("/run/secrets/kubernetes.io/serviceaccount/namespace").trim() @@ -267,6 +268,8 @@ pipeline { openshift.withCluster() { openshift.withProject(params.MBS_INTEGRATION_TEST_BUILD_CONFIG_NAMESPACE) { def build = c3i.buildAndWait("bc/${params.MBS_INTEGRATION_TEST_BUILD_CONFIG_NAME}", + '-e', "MBS_GIT_REPO=${params.MBS_GIT_REPO}", + '-e', "MBS_GIT_REF=${env.PR_NO ? params.MBS_GIT_REF : env.MBS_GIT_COMMIT}", '-e', "MBS_BACKEND_IMAGE=${env.BACKEND_IMAGE_REF}", '-e', "MBS_FRONTEND_IMAGE=${env.FRONTEND_IMAGE_REF}", '-e', "TEST_IMAGES='${env.BACKEND_IMAGE_REF} ${env.FRONTEND_IMAGE_REF}'", diff --git a/openshift/integration/koji/pipelines/templates/mbs-integration-test-template.yaml b/openshift/integration/koji/pipelines/templates/mbs-integration-test-template.yaml index 8140a8d..80e10ba 100644 --- a/openshift/integration/koji/pipelines/templates/mbs-integration-test-template.yaml +++ b/openshift/integration/koji/pipelines/templates/mbs-integration-test-template.yaml @@ -108,6 +108,10 @@ objects: type: JenkinsPipeline jenkinsPipelineStrategy: env: + - name: MBS_GIT_REPO + value: "${MBS_GIT_REPO}" + - name: MBS_GIT_REF + value: "${MBS_GIT_REF}" - name: MBS_BACKEND_IMAGE value: "${MBS_BACKEND_IMAGE}" - name: MBS_FRONTEND_IMAGE diff --git a/openshift/integration/koji/pipelines/templates/mbs-integration-test.Jenkinsfile b/openshift/integration/koji/pipelines/templates/mbs-integration-test.Jenkinsfile index 44f291e..7dd0e5c 100644 --- a/openshift/integration/koji/pipelines/templates/mbs-integration-test.Jenkinsfile +++ b/openshift/integration/koji/pipelines/templates/mbs-integration-test.Jenkinsfile @@ -41,6 +41,7 @@ pipeline { timestamps() timeout(time: 60, unit: 'MINUTES') buildDiscarder(logRotator(numToKeepStr: '10')) + skipDefaultCheckout() } environment { // Jenkins BUILD_TAG could be too long (> 63 characters) for OpenShift to consume @@ -52,6 +53,21 @@ pipeline { script { // Don't set ENVIRONMENT_LABEL in the environment block! Otherwise you will get 2 different UUIDs. env.ENVIRONMENT_LABEL = "test-${env.TEST_ID}" + + // check out specified branch/commit + checkout([$class: 'GitSCM', + branches: [[name: params.MBS_GIT_REF]], + userRemoteConfigs: [[url: params.MBS_GIT_REPO, refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pull/*/head']], + ]) + + // get current commit ID + // FIXME: Due to a bug discribed in https://issues.jenkins-ci.org/browse/JENKINS-45489, + // the return value of checkout() is unreliable. + // Not working: env.MBS_GIT_COMMIT = scmVars.GIT_COMMIT + env.MBS_GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() + echo "Running integration tests for ${params.MBS_GIT_REF}, commit=${env.MBS_GIT_COMMIT}" + + currentBuild.displayName = "${params.MBS_GIT_REF}: ${env.MBS_GIT_COMMIT.take(7)}" } } }