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

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.

Related

Sonarqube stage in jenkins pipeline fails with 403 error

I have a pipeline job which keeps failing on Sonar Quality Gate stage with the below error:
[Bitbucket] Build result notified
org.sonarqube.ws.client.HttpException: Error 403 on http://illinXXXX:XXXXX/api/qualitygates/project_status?analysisId=XXXXXXXX
at org.sonarqube.ws.client.BaseResponse.failIfNotSuccessful(BaseResponse.java:34)
What's more strange, another pipeline from the same MS, is passing that stage.
They both are using the same Sonarquebe user and token, and the same stage syntax.
Sonarqube version: 6.7.1 (build 35068).
Problem:
The execution user/group had permissions to run “Execute Analysis”
Solution:
Update the default template with permissions and push to projects (Bulk Apply Template)
UPDATE
I'm not entirely sure what arielma is saying in the comment marked as the answer, but! checking the box for execute analysis got me passed the 403 issue. Permissions are located under project settings (top right of page next to project information) select groups (near search bar and the All | Users buttons in the list header) then check the appropriate execute analysis check box.

How to Post PR comment from jenkinsfile

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

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 jmeter Performance Metrics Calculation: Check reference values

I have setup TeamCity with JMeter plugin. Under Build Configuration -> Build Features, I selected 'Performance metrics calculation'. I can see the build log is cumulative with previous execution results. However, when checking for failure conditions in the build log for 404 or 500 status code, it always fails if at least one previous instance has these response codes. Without this, the build always says Pass even if there are couple of requests that fail with error codes.
Under 'Check reference values', is it possible to set reference values to check the metrics against responsecode for errors? The only available options are 'Average', '90% line' and 'Max'. Any insight into how I can add options to select and search for error response codes?
Screenshots attached for reference
Thank you.
TeamCity JMeter Performance Metrics Collection
The plugin is open source so theoretically you should be able to add required metric to check.
As a workaround I can suggest using Response Assertion to check response codes. If you need to test only "200" status code - it will be the matter of only one assertion (same level as HTTP Request samplers).
See How to Use JMeter Assertions in Three Easy Steps article for more details on conditionally failing JMeter requests

Any way to customize "Success" label at "Projects" page?

When Teamcity makes successful build, it outputs green "Success" label (or "Tests passed...").
Can I customize this label, for example, output environment variable there?
You can customise the build status message shown for completed builds using the TeamCity service messages. The TeamCity documentation describes in good detail the format for these messages, which just need to be outputted to stdout. Following is an example of the build status message:
##teamcity[buildStatus status='SUCCESS' text='{build.status.text} and some aftertext']
Build Script Interaction with TeamCity documentation

Resources