8

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?

Bruce Becker
  • 3,573
  • 4
  • 19
  • 40
  • Why don't you just use GitHub checks on PRs? https://www.jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step/ – froblesmartin Jul 09 '20 at 08: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 09 '20 at 08: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 09 '20 at 10:49

1 Answers1

7

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/

Bruce Becker
  • 3,573
  • 4
  • 19
  • 40