7

I have a Jenkins instance, with credentials for a "robot" github account, which we use to interact with the GitHub API as a team. Typically, jobs are defined as declarative pipelines. I am looking for the correct syntax to perform the following steps:

  1. At the start of the run, create a review
  2. At the end of each stage, post a review comment, with the status of the stage, e.g. "build passed".
  3. If all of the stages pass, approve the pull request.

I can allow scripted steps, but the pipeline as a whole should be declarative. No shared libraries, and preferably only using commonly-used plugins.

(update with what I have tried)

I have tried using the pipeline github plugin's review method:

pullRequest.review('APPROVE')

naively, but this throws errors.

What would be the correct syntax here?

  • Why don't you just use GitHub checks on PRs? jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step – froblesmartin Jul 9 at 8:13
  • That notifies GitHub of the status of a pull request, not the outcome of a code review. Ie, it says to github "I have tested this commit and it's ok", not "I have conducted a review and I approve this pull request". The difference is that they use different parts of the GitHub API. – Bruce Becker Jul 9 at 8:23
  • 1
    Yes I know, but what is your requirement exactly? If you need to ensure that something, executed by Jenkins, finishes fine and notify about that to a PR, that's what PR checks are meant for, and you can configure branch protection to not allow merges without the required checks green. Then why do you want an automated process to allow or not a PR to be merged, through a review instead of a check? – froblesmartin Jul 9 at 10:49
6

I guess the simplest and direct solution would be to use GitHub API: https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request

But for the requirement you have, PR checks is usually the way to go and you have a plugin that does the API communication for you: https://www.jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step/

| improve this answer | |
  • 2
    Thanks @froblesmartin - your consideration helped me to understand that indeed the best way to go about doing this was to use the API directly. – Bruce Becker Jul 10 at 9:03
  • You are welcome! Glad to help :) – froblesmartin Jul 10 at 9:05
  • 1
    I have a few examples of using the api in a step - would you mind if I edit your answer to add them? – Bruce Becker Jul 10 at 15:43
  • @BruceBecker No problem! Sharing knowledge is always welcome! – froblesmartin Jul 13 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.