mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-02 10:20:31 +08:00
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.
This commit is contained in:
@@ -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 = """<a href="${env.PAGURE_REPO_HOME}/c/${env.MBS_GIT_COMMIT}">${currentBuild.displayName}</a>"""
|
||||
} 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 = """<a href="${env.PR_URL}">PR#${env.PR_NO}</a>"""
|
||||
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 = """<a href="${env.PR_URL}">PR#${env.PR_NO}</a>"""
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user