<p>I guess the simplest and direct solution would be to use GitHub API: <a href="https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request" rel="noreferrer">https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request</a></p>
<p>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: <a href="https://www.jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step/" rel="noreferrer">https://www.jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step/</a></p>

CC BY-SA 4.0
2020-07-10T09:03:10.117Z
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
CC BY-SA 4.0
2020-07-10T09:05:55.787Z
You are welcome! Glad to help :)
froblesmartin
CC BY-SA 4.0
2020-07-10T15:43:40.873Z
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
CC BY-SA 4.0
2020-07-13T06:51:28.763Z
@BruceBecker No problem! Sharing knowledge is always welcome!
froblesmartin
CC BY-SA 4.0
2020-07-09T08:15:24.780Z
2020-07-10T09:02:19.127Z
2020-07-10T09:02:19.127Z
froblesmartin
<p>I have a Jenkins instance, with credentials for a &quot;robot&quot; github account, which we use to interact with the GitHub API as a team. Typically, <strong>jobs are defined as declarative pipelines</strong>. I am looking for the correct syntax to perform the following steps:</p>
<ol>
<li>At the start of the run, create a review</li>
<li>At the end of each stage, post a review comment, with the status of the stage, <em>e.g.</em> &quot;build passed&quot;.</li>
<li>If all of the stages pass, approve the pull request.</li>
</ol>
<p>I can allow scripted steps, but the pipeline as a whole should be declarative. No shared libraries, and preferably only using commonly-used plugins.</p>
<p><em>(update with what I have tried)</em></p>
<p>I have tried using <a href="https://github.com/jenkinsci/pipeline-github-plugin#review" rel="noreferrer">the pipeline github plugin's review method</a>:</p>
<pre><code>pullRequest.review('APPROVE')
</code></pre>
<p>naively, but this throws errors.</p>
<p>What would be the correct syntax here?</p>

CC BY-SA 4.0
2020-07-09T08:13:52.157Z
Why don't you just use GitHub checks on PRs? https://www.jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step/
froblesmartin
CC BY-SA 4.0
2020-07-09T08:23:50.997Z
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
CC BY-SA 4.0
2020-07-09T10:49:18.543Z
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
<jenkins><jenkins-plugins><jenkinsfile><github>
How to have jenkins add a review to a pull request
Bruce Becker
# How to have jenkins add a review to a pull request

(Asked by: username_0 on 2020-07-09)

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:

At the start of the run, create a review
At the end of each stage, post a review comment, with the status of the stage, e.g. "build passed".
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?

**Tags:** jenkins, jenkins-plugins, jenkinsfile, github

> **Comments:**
> **username_1**: Why don't you just use GitHub checks on PRs? https://www.jenkins.io/doc/pipeline/steps/pipeline-githubnotify-step/  
> **username_0**: 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.  
> **username_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?  

---

## 1 answers

### Answer by username_1 on 2020-07-09. Score: 7 | Accepted answer

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/>

> **Comments:**
> **username_0**: Thanks @username_1 - your consideration helped me to understand that indeed the best way to go about doing this was to use the API directly.  
> **username_1**: You are welcome! Glad to help :)  
> **username_0**: I have a few examples of using the api in a step - would you mind if I edit your answer to add them?  
> **username_1**: @BruceBecker No problem! Sharing knowledge is always welcome!  

---

