Discover comment.id

Using the pipeline-github-plugin in a Jenkins pipeline.

You can post a comment to github: pullRequest.comment(commenttext)

To edit the comment later, you’d need to know “comment.id”.

There does seem to be an obscure return value from pullRequest.comment() but it’s not the comment.id. Any idea how to retrieve the id?

Thanks.

COMMENT_ID=$(curl -L -H “Accept: application/vnd.github+json” -H “X-GitHub-Api-Version: 2022-11-28” https://api.github.com/repos/$ORGANIZATION/$REPONAME/issues/${CHANGE_ID}/comments | jq ‘. | select(.body|test(“Some text to recognize”)) | .id’ | tail -n 1)

Experiment 1:

The earlier curl method is interesting and does work.

Next:

The README example contains the answer, hiding in plain sight. (Sometimes that’s easy to miss.) Literally “comment.id”.

Adding a comment

def comment = pullRequest.comment('This PR is highly illogical..')

Editing a comment

pullRequest.editComment(comment.id, 'Live long and prosper.')
// or
comment.body = 'Live long and prosper.'