From 834488d96c85a187682cbffe72f71b315daaa4c8 Mon Sep 17 00:00:00 2001 From: Yuxiang Zhu Date: Mar 21 2019 12:32:15 +0000 Subject: CI/CD: flag commit for post-merge build Follow up https://pagure.io/waiverdb/issue/303: When a post-merge build starts, the commit is marked as 'pending'. When a post-merge build succeeds, the commit is marked as 'success'. When a post-merge build fails, the commit is marked as 'failure'. This PR depends on https://pagure.io/c3i-library/pull-request/10. --- diff --git a/openshift/pipelines/templates/waiverdb-build.Jenkinsfile b/openshift/pipelines/templates/waiverdb-build.Jenkinsfile index d048535..5444a5a 100644 --- a/openshift/pipelines/templates/waiverdb-build.Jenkinsfile +++ b/openshift/pipelines/templates/waiverdb-build.Jenkinsfile @@ -138,14 +138,23 @@ pipeline { } pagureLink = """PR#${env.PR_NO}: ${escapeHtml(prInfo.title)}""" // set PR status to Pending - setBuildStatusOnPagurePR(null, 'Pending') + if (params.PAGURE_API_KEY_SECRET_NAME) + setBuildStatusOnPagurePR(null, 'Building...') } catch (Exception e) { echo "Error using pagure API: ${e}" } currentBuild.description = pagureLink - } else { + } else { // is a branch currentBuild.displayName = "${env.WAIVERDB_GIT_REF}: ${env.WAIVERDB_GIT_COMMIT.substring(0, 7)}" currentBuild.description = """${currentBuild.displayName}""" + if (params.PAGURE_API_KEY_SECRET_NAME) { + try { + flagCommit('pending', null, 'Building...') + echo "Updated commit ${env.WAIVERDB_GIT_COMMIT} status to PENDING." + } catch (e) { + echo "Error updating commit ${env.WAIVERDB_GIT_COMMIT} status to PENDING: ${e}" + } + } } } } @@ -430,8 +439,8 @@ pipeline { } success { script { - // updating Pagure PR flag and make a comment - if (env.PR_NO && params.PAGURE_API_KEY_SECRET_NAME) { + // on pre-merge workflow success + if (params.PAGURE_API_KEY_SECRET_NAME && env.PR_NO) { try { setBuildStatusOnPagurePR(100, 'Build passed.') echo "Updated PR #${env.PR_NO} status to PASS." @@ -439,18 +448,29 @@ pipeline { echo "Error updating PR #${env.PR_NO} status to PASS: ${e}" } } + // on post-merge workflow success + if (params.PAGURE_API_KEY_SECRET_NAME && !env.PR_NO) { + try { + flagCommit('success', 100, 'Build passed.') + echo "Updated commit ${env.WAIVERDB_GIT_COMMIT} status to PASS." + } catch (e) { + echo "Error updating commit ${env.WAIVERDB_GIT_COMMIT} status to PASS: ${e}" + } + } } } failure { script { - // updating Pagure PR flag - if (env.PR_NO && params.PAGURE_API_KEY_SECRET_NAME) { + // on pre-merge workflow failure + if (params.PAGURE_API_KEY_SECRET_NAME && env.PR_NO) { + // updating Pagure PR flag try { setBuildStatusOnPagurePR(0, 'Build failed.') echo "Updated PR #${env.PR_NO} status to FAILURE." } catch (e) { echo "Error updating PR #${env.PR_NO} status to FAILURE: ${e}" } + // making a comment try { commentOnPR(""" Build ${env.WAIVERDB_GIT_COMMIT} [FAILED](${env.BUILD_URL})! @@ -461,12 +481,24 @@ pipeline { echo "Error making a comment on PR #${env.PR_NO}: ${e}" } } - // sending email - if (params.MAIL_ADDRESS){ - try { - sendBuildStatusEmail('failed') - } catch (e) { - echo "Error sending email: ${e}" + // on post-merge workflow failure + if (!env.PR_NO) { + // updating Pagure commit flag + if (params.PAGURE_API_KEY_SECRET_NAME) { + try { + flagCommit('failure', 0, 'Build failed.') + echo "Updated commit ${env.WAIVERDB_GIT_COMMIT} status to FAILURE." + } catch (e) { + echo "Error updating commit ${env.WAIVERDB_GIT_COMMIT} status to FAILURE: ${e}" + } + } + // sending email + if (params.MAIL_ADDRESS){ + try { + sendBuildStatusEmail('failed') + } catch (e) { + echo "Error sending email: ${e}" + } } } } @@ -499,6 +531,12 @@ def setBuildStatusOnPagurePR(percent, String comment) { url: env.BUILD_URL, percent: percent, comment: comment, pr: env.PR_NO) } } +def flagCommit(status, percent, comment) { + withPagureCreds { + it.flagCommit(username: 'c3i-jenkins', uid: 'ci-post-merge', status: status, + url: env.BUILD_URL, percent: percent, comment: comment, commit: env.WAIVERDB_GIT_COMMIT) + } +} def commentOnPR(String comment) { withPagureCreds { it.commentOnPR(comment: comment, pr: env.PR_NO)