From 2db62eb8974a5c615524ffcb184e7e84e4135d51 Mon Sep 17 00:00:00 2001 From: Matt Prahl Date: May 16 2019 13:31:44 +0000 Subject: Merge #1258 `Run the integration tests from the current branch` --- 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)}" } } }