From 6f2513906638ceca46ab64829e26aa81ee80b3cc Mon Sep 17 00:00:00 2001 From: Yuxiang Zhu Date: Oct 16 2018 02:53:51 +0000 Subject: Fix PR build and doc push commit message OpenShift Build Strategy doesn't build Pagure pull-requests because Pagure PRs follow `pull//head` format and there is no options in OpenShift BuildConfig to specify custom refspec like `+refs/pull/*/head:refs/remotes/origin/pull/*/head`. This PR will change the way of tracking a Git commit with ref name to work around this issue, although the actual commit behind a Git ref may change during multiple Git checkouts. --- diff --git a/openshift/pipelines/templates/waiverdb-dev.Jenkinsfile b/openshift/pipelines/templates/waiverdb-dev.Jenkinsfile index 93ae5b2..d079f1f 100644 --- a/openshift/pipelines/templates/waiverdb-dev.Jenkinsfile +++ b/openshift/pipelines/templates/waiverdb-dev.Jenkinsfile @@ -85,9 +85,8 @@ pipeline { } def scmVars = checkout([$class: 'GitSCM', branches: [[name: params.WAIVERDB_GIT_REF]], - userRemoteConfigs: [[url: params.WAIVERDB_GIT_REPO]], + userRemoteConfigs: [[url: params.WAIVERDB_GIT_REPO, refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pull/*/head']], ]) - env.WAIVERDB_GIT_COMMIT_ID = scmVars.GIT_COMMIT // Generate a version-release number for the target Git commit def versions = sh(returnStdout: true, script: 'source ./version.sh && echo -en "$WAIVERDB_VERSION\n$WAIVERDB_CONTAINER_VERSION"').split('\n') env.WAIVERDB_VERSION = versions[0] @@ -166,7 +165,7 @@ pipeline { if [[ "$(git diff --cached --numstat | wc -l)" -eq 0 ]] ; then exit 0 # No changes, nothing to commit fi - git commit -m 'Automatic commit of docs built by Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER}' + git commit -m "Automatic commit of docs built by Jenkins job ${JOB_NAME} #${BUILD_NUMBER}" git push origin master ''' } @@ -220,7 +219,7 @@ pipeline { def processed = openshift.process(template, "-p", "NAME=${env.BUILDCONFIG_INSTANCE_ID}", '-p', "WAIVERDB_GIT_REPO=${params.WAIVERDB_GIT_REPO}", - '-p', "WAIVERDB_GIT_REF=${env.WAIVERDB_GIT_COMMIT_ID}", + '-p', "WAIVERDB_GIT_REF=${params.WAIVERDB_GIT_REF}", '-p', "WAIVERDB_IMAGE_TAG=${env.TEMP_TAG}", '-p', "WAIVERDB_VERSION=${env.WAIVERDB_VERSION}", '-p', "WAIVERDB_IMAGESTREAM_NAME=${params.WAIVERDB_IMAGESTREAM_NAME}", @@ -291,7 +290,7 @@ pipeline { def buildSelector = testBcSelector.startBuild( '-e', "IMAGE=${env.RESULTING_IMAGE_REPO}:${env.RESULTING_TAG}", '-e', "WAIVERDB_GIT_REPO=${params.WAIVERDB_GIT_REPO}", - '-e', "WAIVERDB_GIT_REF=${env.WAIVERDB_GIT_COMMIT_ID}", + '-e', "WAIVERDB_GIT_REF=${params.WAIVERDB_GIT_REF}", ) timeout(5) { // 5 min buildSelector.watch { diff --git a/openshift/pipelines/templates/waiverdb-integration-test.Jenkinsfile b/openshift/pipelines/templates/waiverdb-integration-test.Jenkinsfile index d14529c..233aec5 100644 --- a/openshift/pipelines/templates/waiverdb-integration-test.Jenkinsfile +++ b/openshift/pipelines/templates/waiverdb-integration-test.Jenkinsfile @@ -44,7 +44,7 @@ pipeline { steps { checkout([$class: 'GitSCM', branches: [[name: params.WAIVERDB_GIT_REF]], - userRemoteConfigs: [[url: params.WAIVERDB_GIT_REPO]], + userRemoteConfigs: [[url: params.WAIVERDB_GIT_REPO, refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pull/*/head']], ]) } } diff --git a/openshift/pipelines/templates/waiverdb-polling-pagure.yaml b/openshift/pipelines/templates/waiverdb-polling-pagure.yaml index 64d5ba5..1fa2c7a 100644 --- a/openshift/pipelines/templates/waiverdb-polling-pagure.yaml +++ b/openshift/pipelines/templates/waiverdb-polling-pagure.yaml @@ -139,31 +139,32 @@ objects: steps { script { // checking out the polled branch - def polledBranch = env.PAGURE_POLLING_FOR_PR == 'true' ? 'origin/pr/*' : "origin/${PAGURE_POLLED_BRANCH}" + def polledBranch = env.PAGURE_POLLING_FOR_PR == 'true' ? 'origin/pull/*/head' : "origin/${PAGURE_POLLED_BRANCH}" def scmVars = checkout([$class: 'GitSCM', branches: [[name: polledBranch]], userRemoteConfigs: [ [ name: 'origin', url: env.GIT_URL, - refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pr/*', + refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*/head:refs/remotes/origin/pull/*/head', ], ], extensions: [[$class: 'CleanBeforeCheckout']], ]) - echo "Build on branch=${scmVars.GIT_BRANCH}, commit=${scmVars.GIT_COMMIT}" env.GIT_COMMIT = scmVars.GIT_COMMIT env.GIT_AUTHOR_EMAIL = scmVars.GIT_AUTHOR_EMAIL // setting build display name def prefix = 'origin/' def branch = scmVars.GIT_BRANCH.startsWith(prefix) ? scmVars.GIT_BRANCH.substring(prefix.size()) - : scmVars.GIT_BRANCH // origin/pr/1234 -> pr/1234, origin/master -> master + : scmVars.GIT_BRANCH // origin/pull/1234/head -> pull/1234/head, origin/master -> master + env.GIT_BRANCH = branch + echo "Build on branch=${env.GIT_BRANCH}, commit=${env.GIT_COMMIT}" if (env.PAGURE_POLLING_FOR_PR == 'false' && branch == "${PAGURE_POLLED_BRANCH}") { echo 'Building master' currentBuild.displayName = "${PAGURE_POLLED_BRANCH}" } - else if (env.PAGURE_POLLING_FOR_PR == 'true' && branch ==~ /^pr\/[0-9]+$/) { - env.PR_NO = branch.split('/')[-1] + else if (env.PAGURE_POLLING_FOR_PR == 'true' && branch ==~ /^pull\/[0-9]+\/head$/) { + env.PR_NO = branch.split('/')[1] env.PR_URL = "${env.PAGURE_REPO_HOME}/pull-request/${env.PR_NO}" // To HTML syntax in build description, go to `Jenkins/Global Security/Markup Formatter` and select 'Safe HTML'. def pagureLink = """PR-${env.PR_NO}""" @@ -196,7 +197,7 @@ objects: def isMaster = env.PAGURE_POLLING_FOR_PR != 'true' def devBuild = bcSelector.startBuild( '-e', "WAIVERDB_GIT_REPO=${env.GIT_URL}", - '-e', "WAIVERDB_GIT_REF=${env.GIT_COMMIT}", + '-e', "WAIVERDB_GIT_REF=${env.GIT_BRANCH}", '-e', "FORCE_PUBLISH_IMAGE=${isMaster}", '-e', "FORCE_PUBLISH_DOCS=${isMaster}", '-e', "WAIVERDB_MAIN_BRANCH=${PAGURE_POLLED_BRANCH}",