Add a comment in github pull request in jenkins

前端 未结 1 480
旧时难觅i
旧时难觅i 2021-01-06 09:15

I am using Git pull request builder plugin in Jenkins to link the Pull requests to Jenkins. Jobs are triggered with hooks and everything runs smoothly.

Nevertheless,

1条回答
  •  攒了一身酷
    2021-01-06 10:13

    I couldn't find a plugin doing it, so I did using curl. Here is my groovy function

    def call(def text_pr) {
      def repository_url = scm.userRemoteConfigs[0].url
      def repository_name = repository_url.replace("git@github.com:","").replace(".git","")
    
      withCredentials([string(credentialsId: '', variable: 'GITHUB_TOKEN')]) {
        sh "curl -s -H \"Authorization: token ${GITHUB_TOKEN}\" -X POST -d '{\"body\": \"${text_pr}\"}' \"https://api.github.com/repos/${repository_name}/issues/${ghprbPullId}/comments\""
      }
    }
    

    0 讨论(0)
提交回复
热议问题