Can I cancel a TeamCity build from my msbuild script? - msbuild

TeamCity allows me to report back from my MsBuild script using the ##teamcity interaction. I can use this to tell TeamCity that the build has FAILED, or indeed SUCCEEDED, however I would like to tell it to CANCEL the build instead. Does anyone know of a way to do this?
I can use this to inform TeamCity of failure...
<Message Text="##teamcity[buildStatus status='FAILURE']" Condition="Something==SomeCondition" />
I would love to do this...
<Message Text="##teamcity[buildStatus status='CANCEL']" Condition="Something==SomeCondition" />
I've tried out the TeamCity Service Tasks but nothing thus far.
EDIT:
So it seems this feature is not available, although a workaround http request can be used to cancel a build. There is also a feature request for Cancelling a build the TC website.

According to JetBrains issue tracker and release page, since TeamCity 2019.1 EAP 1 builds can be stopped with service message as in:
##teamcity[buildStop comment='canceling comment' readdToQueue='true']

You can use the undocumented http request which has changed since it was originally posted. You now need "operationKind=1". I used a powershell runner like so:
$buildId = %teamcity.build.id%
$uri = "http://teamcity/ajax.html?guest=1&comment=Cancelling+build+for+some+reason&submit=Stop&buildId=$buildId&kill&operationKind=1"
$response = Invoke-WebRequest -UseBasicParsing -Uri $uri
Another SO post can tell you how to make an http request from MSBuild
The "guest=1" means I'm using the guest account, which at minimum needs the "Stop build / remove from queue" for the project you're going to cancel.

Since Teamcity 8.1 (Source) it is possible to Cancel the Build via REST API.
Taken from the 9.x Documentation, cancelling a currently running build
curl -v -u user:password --request POST "http://teamcity:8111/app/rest/builds/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"

Can you not just use the Error task, this should cause the execution of the build to stop.

Related

How to download the latest log of a Bamboo job?

I want to download the latest log of a Bamboo job programmatically to parse its content and display in a dashboard.
However, Bamboo does not provide a direct link (e.g. with "latest" in URL similar to artifacts download) or to make the Bamboo build log as an artifact.
Someone who has worked around this issue, please share the knowledge.
Check out the REST API offered for bamboo builds: https://docs.atlassian.com/bamboo/REST/6.0.0/
Here's one example from Atlassian's community: https://community.atlassian.com/t5/Answers-Developer-Questions/How-do-you-get-the-build-log-using-REST-API/qaq-p/485212
See "expand": https://docs.atlassian.com/bamboo/REST/6.0.0/#d2e485
... expands build result details on request. Possible values are: changes, metadata, artifacts, comments, labels, jiraIssues, stages, logEntries. stages expand is available only for top level plans. It allows to drill down to job results using stages.stage.results.result. logEntries and testResults are available only for job results
At least as of Bamboo 6.7.1 (and possibly earlier versions), you can issue a request directly for the log using a Script Task, curl, and Bamboo variables:
curl -X GET --user username:password \
"http://localhost:8085/download/${bamboo.buildKey}/build_logs/${bamboo.buildResultKey}.log"
That will give you the textual output of the log.

Trigger TeamCity build on a specific BitBucket repo branch

I'm trying to trigger a TeamCity build using the REST API on a specific branch in a repository. However, it is always fetching the code from the master branch (which is the default one). Not sure where I am doing it wrong. Is there anything else I need to set up on the TeamCity to turn on this feature?
My curl is:
curl -v -u uname:pwd http://remoteserver.com:8111/httpAuth/app/rest/buildQueue --request POST --header "Content-Type:application/xml" --data-binary #build.xml
And my build.xml is:
<build branchName="testBranch">
<buildType id="TestTc_TestTc"/>
</build>
I'm using TeamCity 9. Could anyone help me on where I am doing it wrong?
I have added "+:refs/heads/(*)" under Branch Specification in the VCS Root settings and it worked fine.

How does one remove (unregister) a runtime (not component) from the NoFlo Development Environment

I am running a local version of the NoFlo Development Environment and would like to know how to remove (unregister) a runtime. Actually, how can I remove a runtime from the FlowHub hosted environment, as well?
There is currently no UI to do this, but the API exists: Issue
Here is my bash script for doing just that.
#!/bin/bash -x
# Your UUID can be found through developer JS console: Resources -> Local Storage -> Look for grid-token
uuid="<your uuid>"
# the list of runtimes you want to delete.
list=$1
for i in ${list}
do
curl -X DELETE http://api.flowhub.io/runtimes/${i} -H "Authorization: Bearer ${uuid}"
done

Send build status from Travis to Sauce Labs

I have my testing up and running with Travis/SauceLabs. Now I would like to add a SauceLabs test badge to my repo.
I added the badge markdown to my Readme file but how can I send the build pass/fail to SauceLabs? I found this instructions for Selenium,
Key: passed
Value type: bool
Example: "passed": true
but how/where do I add info in my files for my Grunt-Karma/Travis/SauceLabs testing?
The Karma-Sauce-Launcher was using the wrong id, and this was fixed on Github by this PR and released in NPM as version 0.2.5
Aditionally the saucelabs reporter has to be added to the gruntfile options, besides the existing ones or the default progress.
So the bugfix I added to my package.json:
"karma-sauce-launcher": "~0.2.5"
and added this:
reporters: ['progress', 'saucelabs'],
in the Karma options.
You have to use the REST API. What you would do is add code in a function that is executed at the very end of your test suite and knows the result of your test run. This code would have to perform a query equivalent to this curl command:
$ curl -H "Content-Type:text/json" -s -X PUT -d '{"passed": <status>}' http://<username>:<key>#saucelabs.com/rest/v1/<username>/jobs/<job-id>
(The identifiers in angular brackets have to be replaced with appropriate values.)
I've done it with Python but I don't have JavaScript code to share. And by the way, you have to do this for Selenium too because as the documentation states, when Selenium sends the job data to Sauce Labs, it cannot know yet what the test result is going to be.
If you're using Grunt already, you should use https://github.com/axemclion/grunt-saucelabs as it is the official plug-in that is worked on by devs from SauceLabs.

Make an HTTP request from MSBuild script

I'm looking for a way to hit a web app/restful service URL from msbuild script to trigger remote procedure.
Is there any way how I can do that except calling that external app?
Ideally I'm looking for a way to break a build sequence if service returned something else that http 200
I use the MSBuild Community Tasks a lot. They add extra tasks for MSBuilds. In there is a HttpRequest task which, from the look of it, does what you want.
<HttpRequest Url="http://<mydomain.com>/index.php?checkdb=1"
EnsureResponseContains="Database upgrade check completed successfully."
FailOnNon2xxResponse="true" />
Hope this helps
In version 4 of the MSBuild Community Tasks, the HttpRequest task was replaced by HttpWebRequest with a different syntax:
<MSBuild.ExtensionPack.Web.HttpWebRequest
TaskAction="GetResponse" Url="http://www.freetodev.com">
<Output TaskParameter="Response" ItemName="ResponseDetail"/>
<Output TaskParameter="Status" PropertyName="ResponseStatus"/>
</MSBuild.ExtensionPack.Web.HttpWebRequest>