From e91cf37bf7e7b9af02da7c7b59dea01a8315fba7 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Wed, 26 Jun 2019 14:09:28 -0400 Subject: [PATCH] ignore PRs that aren't Open Sometimes it is necessary recreate the Jenkins PR polling job, or cleanup old runs. This can cause Jenkins to lose the record of which PRs it has already seen, and retest old PRs which are long closed. This change causes the polling job to check the state of the PR, and ignore it if it isn't Open. Testing PRs which are in any other state doesn't provide any value. --- .../templates/mbs-polling-pagure.yaml | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/openshift/integration/koji/pipelines/templates/mbs-polling-pagure.yaml b/openshift/integration/koji/pipelines/templates/mbs-polling-pagure.yaml index 9e5b377f..04221b52 100644 --- a/openshift/integration/koji/pipelines/templates/mbs-polling-pagure.yaml +++ b/openshift/integration/koji/pipelines/templates/mbs-polling-pagure.yaml @@ -90,6 +90,8 @@ objects: jenkinsPipelineStrategy: jenkinsfile: |- // Don't use external Jenkinsfile here, or Jenkins will also poll on that repo and branch + library identifier: 'c3i@master', changelog: false, + retriever: modernSCM([$class: 'GitSCMSource', remote: 'https://pagure.io/c3i-library.git']) pipeline { agent { kubernetes { @@ -131,10 +133,12 @@ objects: environment { PIPELINE_NAMESPACE = readFile('/run/secrets/kubernetes.io/serviceaccount/namespace').trim() PAGURE_URL = "${PAGURE_URL}" + PAGURE_API = "${env.PAGURE_URL}/api/0" + PAGURE_REPO_NAME = "${PAGURE_REPO_NAME}" PAGURE_REPO_IS_FORK = "${PAGURE_REPO_IS_FORK}" PAGURE_POLLING_FOR_PR = "${PAGURE_POLLING_FOR_PR}" - PAGURE_REPO_HOME = "${env.PAGURE_URL}${env.PAGURE_REPO_IS_FORK == 'true' ? '/fork' : ''}/${PAGURE_REPO_NAME}" - GIT_URL = "${env.PAGURE_URL}/${env.PAGURE_REPO_IS_FORK == 'true' ? 'forks/' : ''}${PAGURE_REPO_NAME}.git" + PAGURE_REPO_HOME = "${env.PAGURE_URL}${env.PAGURE_REPO_IS_FORK == 'true' ? '/fork' : ''}/${env.PAGURE_REPO_NAME}" + GIT_URL = "${env.PAGURE_URL}/${env.PAGURE_REPO_IS_FORK == 'true' ? 'forks/' : ''}${env.PAGURE_REPO_NAME}.git" PREMERGE_JOB_NAME = "${PREMERGE_JOB_NAME}" POSTMERGE_JOB_NAME = "${POSTMERGE_JOB_NAME}" } @@ -169,12 +173,20 @@ objects: currentBuild.description = """${currentBuild.displayName}""" } 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}""" - echo "Building PR #${env.PR_NO}: ${env.PR_URL}" - currentBuild.displayName = "PR#${env.PR_NO}" - currentBuild.description = pagureLink + def prInfo = withPagure { + it.getPR(env.PR_NO) + } + if (prInfo.status == 'Open') { + 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}""" + echo "Building PR #${env.PR_NO}: ${env.PR_URL}" + currentBuild.displayName = "PR#${env.PR_NO}" + currentBuild.description = pagureLink + } else { + echo "Skipping PR#${env.PR_NO} because it is ${prInfo.status}" + env.SKIP = 'true' + } } else { // This shouldn't happen. error("Build is aborted due to unexpected polling trigger actions.") } @@ -209,6 +221,11 @@ objects: } } stage('Build') { + when { + not { + environment name: 'SKIP', value: 'true' + } + } steps { script { openshift.withCluster() { @@ -231,3 +248,10 @@ objects: } } } + def withPagure(args=[:], cl) { + args.apiUrl = env.PAGURE_API + args.repo = env.PAGURE_REPO_NAME + args.isFork = env.PAGURE_REPO_IS_FORK == 'true' + def pagureClient = pagure.client(args) + return cl(pagureClient) + }