#267 adding pagure PR status update
Merged 5 years ago by lholecek. Opened 5 years ago by jmolet.
jmolet/greenwave pr-updater  into  master

file modified
+35 -5
@@ -2,8 +2,15 @@ 

   * SPDX-License-Identifier: GPL-2.0+

   */

  

+ // 'global' var to store git info

+ def scmVars

+ 

  try { // massive try{} catch{} around the entire build for failure notifications

  

+ node('master'){

+     scmVars = checkout scm

+ }

+ 

  timestamps {

  node('fedora-27') {

      checkout scm
@@ -220,9 +227,7 @@ 

  

  node('docker') {

      checkout scm

-     /* Can't use GIT_BRANCH because of this issue https://issues.jenkins-ci.org/browse/JENKINS-35230 */

-     def git_branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()

-     if (git_branch == 'master') {

+     if (scmVars.GIT_BRANCH == 'origin/master') {

          stage('Tag "latest".') {

              unarchive mapping: ['appversion': 'appversion']

              def appversion = readFile('appversion').trim()
@@ -253,9 +258,11 @@ 

      currentBuild.result = 'FAILURE'

      throw e

  } finally {

+     // if result hasn't been set to failure by this point, its a success.

+     def currentResult = currentBuild.result ?: 'SUCCESS'

+ 

+     // send pass/fail email

      if (ownership.job.ownershipEnabled) {

-         // if result hasn't been set to failure by this point, its a success.

-         def currentResult = currentBuild.result ?: 'SUCCESS'

          def previousResult = currentBuild.previousBuild?.result

          def SUBJECT = ''

          def BODY = "${env.BUILD_URL}"
@@ -273,4 +280,27 @@ 

                       body: BODY

          }

      }

+ 

+     // update Pagure PR status

+     def pagurePR = scmVars.GIT_BRANCH.split('/')[-1]  // origin/pr/1234 -> 1234

+     if (pagurePR ==~ /[0-9]+/) {  // PR's will only be numbers on pagure

+         def resultPercent = (currentResult == 'SUCCESS') ? '100' : '0'

+         def resultComment = (currentResult == 'SUCCESS') ? 'Build passed.' : 'Build failed.'

+         def pagureRepo = new URL(scmVars.GIT_URL).getPath() - ~/^\// - ~/.git$/  // https://pagure.io/my-repo.git -> my-repo

+ 

+         withCredentials([string(credentialsId: "${env.PAGURE_API_TOKEN}", variable: 'TOKEN')]) {

+         build job: 'pagure-PR-status-updater',

+             propagate: false,

+             parameters: [

+                 // [$class: 'StringParameterValue', name: 'PAGURE_REPO', value: 'https://pagure.io'],  // not needed if https://pagure.io

+                 [$class: 'StringParameterValue', name: 'PAGURE_PR', value: pagurePR],

+                 [$class: 'StringParameterValue', name: 'PAGURE_REPO', value: pagureRepo],

+                 [$class: 'StringParameterValue', name: 'PERCENT_PASSED', value: resultPercent],

+                 [$class: 'StringParameterValue', name: 'COMMENT', value: resultComment],

+                 [$class: 'StringParameterValue', name: 'REFERENCE_URL', value: "${env.BUILD_URL}"],

+                 [$class: 'StringParameterValue', name: 'REFERENCE_JOB_NAME', value: "${env.JOB_NAME}"],

+                 [$class: 'hudson.model.PasswordParameterValue', name: 'TOKEN', value: "${env.TOKEN}"]

+                         ]

+         }

+     }

  }

Adding pagure PR status updates and cleaning up a work around for getting the current git status.

Work in progress right now, using this to test the PR status updater....

1 new commit added

  • testing
5 years ago

1 new commit added

  • testing
5 years ago

1 new commit added

  • test
5 years ago

Hmm, seems like our jenkins needs to have its git plugin updated due to this bug: https://issues.jenkins-ci.org/browse/JENKINS-48061

1 new commit added

  • test
5 years ago

rebased onto 1cd5a3cc25efae207ebcd0d07f4e53449c2145bd

5 years ago

rebased onto fb515b563b2dad51ce39f1482882f4a3f6410d3a

5 years ago

Wow it finally worked. I think this PR is good to go. For this feature check out the "Jenkins" (build passed.) link on the side of this comment chain. Going to add this to the other projects...

rebased onto 3c3842c

5 years ago

Pull-Request has been merged by lholecek

5 years ago
Metadata