How to Post PR comment from jenkinsfile - jenkins-pipeline

I am running Multibranch pipeline jobs using Github plugin with the option below
and periodical polling (5 mins) to look for open pull requests (new feature branches in our case). Open pull request is identified, job is triggered and on successful completion am able to update the status. would like to add a PR status message with URL using
pullRequest.comment('This is a comment sent from the Pipeline').
But pipeline job fails with
"No such property: pullRequest for class: groovy.lang.Binding".
on further inspection, env.CHANGE_ID is set to NULL (means it is not a PR build job which is a prerequisite to use pullRequest module). can anyone suggest some idea to get CHANGE_ID set or means to post/update comments to PR other than success or Fail

Related

Approved PR comment response re-deploys GitHub workflow

I have a workflow with the following triggering mechanism:
on:
pull_request_review:
types: [submitted]
jobs:
job_one:
if: github.event.review.state == 'approved'
It works exactly as expected so upon PR approval, the workflow is deployed. However, if anyone leaves a comment within the approval, and a response is added to that comment, the workflow deploys again but the job is skipped. How can I avoid deploying the workflow when a response is added to a PR comment? It overwrites the active checks and is visually confusing even though the workflow is still running.

trigger TeamCity build when comment on GitHub pull request

I'd like to trigger build by commenting specific message on the pull request, like: "Build again."
I allowed all 'commit', 'PR', and 'comment' things to GitHub-TeamCity hook.
Then I tried with VCS Trigger's 'comment' rule, but no luck.
I'm used to triggering build by comment with Jenkins using this plug-in: https://plugins.jenkins.io/github-pr-comment-build
Is there any plug-in or instructions for TeamCity?
I've looked this SO, and I agree with the chosen answer. However, I found that triggering something via comment is quite handy, and it gives more extensibility such as Slack integration.
TeamCity trigger for Github comment on pull request

Where in the logs is the Status Message of the Background (async) workflow Stop step?

I have a background workflow that ends with a Stop step. This step has an optional Status Message attribute that I populate with some details I need to be logged.
After the workflow has run I can find the workflow Status Reason (="Succeeded") and other details in the corresponding System Job record. I would also expect to find the stored info in the Message field, but it's not there. I've tried static and dynamic Status Messages, but no success with neither.
Does anybody know where that message is stored?
Basically the Message in Details section of System Job is a placeholder for some useful error message/logging tracker to log with the help of ITracingService.Trace by developer or by platform when something breaks/exception captured.
The status reason is not the good place for logging success scenario message, rather for canceled scenario to pop custom message to user & rolling back the transaction.
Not sure why you want to store there, but better use a custom field or even a note (annotation) can help you in better way. Avoid storing successful workflow execution logs anyway.
Check in system jobs:
Also, uncheck this value:
Then, you could try running the workflow sync. I prefer this than waiting for the async service.

Jenkinsfile : Posting test info back to github?

I am using a Jenkinsfile to build build pull requests (declarative pipeline) , I want to push test results (one line) , code coverage(cobertura) and if possible SONAR back into the pull request in a fairly simple fashion.
I looked at some docs and added
junit 'target/surefire-reports/*.xml
but it doesn't post anything back to the pull request in github.
As far as I know, you cannot push test results back to GitHub without actually using git commit/push. What you can actually do is to create a webhook (setup guide) on GitHub and on Jenkins so that the build result is showed on GitHub and clicking on that link can redirect you to the Jenkins server.
Example
For Sonar I am sure there is a webhook as well, but I haven't used it personally.

Teamcity REST API: How to get agent of last successful build

Is there a way in Teamcity REST API to get the agent name of the last successful build. I am using Teamcity 8.0.6. I tried this
http://<TeamcityServer>/httpAuth/app/rest/buildTypes/id:BuildId/builds?status=SUCCESS
But the result returned doesn't contain Agent name.
The following will give you the last successful build details for a given build type (where BUILDTYPE is the btxxx id):
http://<TeamcityServer>/httpAuth/app/rest/builds/buildType:(id:BUILDTYPE),status:SUCCESS
The response contains the agent details in the /build/agent element.

Resources