Is it possible to tag TeamCity builds using service messages (or some other programatic way)? - teamcity-8.0

Is it possible to tag TeamCity builds using service messages or some other programmatic way from a build step maybe...?
How can this be done?

See also the following stackoverflow discussion:
Programatically pin a build in Teamcity
Moreover, since there were two open questions on stackoverflow and I had the same problem, I wrote a TeamCity plugin that solves it:
https://github.com/echocat/teamcity-buildTagsViaBuildLog-plugin

There is a VCS labelling in TeamCity, you can tag when a build successful, or on each build. Does it correspond to what you're looking for?

Yes, there is. You can use the REST API, as described here. Basically,
Adding a tag using plain text
curl -s --header "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/plain' \
"https://ci.ACME.com/app/rest/builds/5375/tags --data tag-1
tag-1
Reading the list of tags as json
curl -s -H 'Accept: application/json' \
-H "Authorization: Bearer $TOKEN" \
"https://ci.ACME.com/app/rest/builds/5375/tags"
{"count":1,"tag":[{"name":"tag-1"}]}
Overwriting tags using json, getting it back as xml (the default)
curl -s --header "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' -X PUT \
"https://ci.ACME.com/app/rest/builds/5375/tags \
--data '{"count":2,"tag":[{"name":"tag-A"},{"name":"tag-B"}]}'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><tags count="2"><tag name="tag-A"/><tag name="tag-B"/></tags>

Related

Convert cURL To Applescript

I am trying to convert a cURL command to AppleScript Using "do shell script".
I've used various hints from previous posts but I'm still running into errors.
Can anyone point out errors in my syntax.
The below script works fine when run in terminal.
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header 'Authorization: Bearer MYTOKEN' \
--header 'Content-Type: application/octet-stream' \
--header 'Dropbox-API-Arg: {"path":"/RoomVT/Clown2.jpeg"}'
--data-binary #"/Splash.jpeg"
I then adapt as.
--Add do shell script Command--
--Place The cURL Inside Double Quotes--
--Replace Double Quotes With Single Quotes--
--Remove Backslashes At End Of Lines--
--You May Also Need To Place All In A Single Line--
do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload --header 'Authorization: Bearer MYTOKEN' --header 'Content-Type: application/octet-stream' --header 'Dropbox-API-Arg: {'path':'/RoomVT/Clown2.jpeg'}' --data-binary #'/Splash.jpeg'"
I still get the error.
"Error in call to API function \"files/upload\": HTTP header \"Dropbox-API-Arg\": could not decode input as JSON"
Thanks for your comments.
I went with #RobC suggestion and it worked first time.
do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload --header 'Authorization: Bearer b4Itg9wetFIAAAAAAAAD7PPkCmoIE2oXvkx_-nq1L2D5G7Bfla-5LHKHtJqoeBMc' --header 'Content-Type: application/octet-stream' --header 'Dropbox-API-Arg: {\"path\":\"/EngineRoomVT/Clown2.jpeg\"}' --data-binary #\"/Splash.jpeg\""

Correct way to add teams to repository with curl

Trying to add an org team to a repo but am unable to with the following:
curl -H "Authorization: token tokenID" -H "Content-Length: 0" -X put \
> -d "" https://url/api/v3/teams/23/repos/johndoe/repo-name
https://developer.github.com/v3/teams/#add-or-update-team-repository
Fro the documentation and this blog post, you must provide a custom media type in the Accept header:
application/vnd.github.hellcat-preview+json
With curl:
curl -H "Content-Type: application/vnd.github.hellcat-preview+json"...

JSON data is invalid

I am trying to cURL an API for speech transcription, but am getting the error JSON data is invalid. It is very likely that this is an API specific error, however, I was wondering whether it was an issue with my cURL command.
curl --request POST --url "https://api.assemblyai.com/transcript" \
--header "authorization: abc123" --data \
"{audio_src_url: https://s3-us-west-2.amazonaws.com/blog.assemblyai.com/audio/8-7-2018-post/7510.mp3}"
The documentation is the first example at this link and I am using Windows cmd.
You need double quotes around the keys and the values.
curl --request POST --url "https://api.assemblyai.com/transcript" \
--header "authorization: abc123" --data \
"{\"audio_src_url\": \"https://s3-us-west-2.amazonaws.com/blog.assemblyai.com/audio/8-7-2018-post/7510.mp3\"}"

Curl to Advanced rest Client

i need to send below curl command using rest client
curl -X POST -H "Content-Type: application/json"
\ -H "Authorization: Basic MzUzYjMwMmM0NDU3NGY1NjUwNDU2ODdlNTM0ZTdkNmE6Mjg2OTI0Njk3ZTYxNWE2NzJhNjQ2YTQ5MzU0NTY0NmM="
\ -d '{"user":{"emailAddress":"test#example.com"}, "password":"password"}'
\ 'http://localhost:8080/oauth2-provider/v1.0/users'
so far i have managed to put it like above screen but im not sure how to
put
-d '{"user":{"emailAddress":"test#example.com"}, "password":"password"}'
in rest client
there is a section below for "payload"
that is where the json that you have should be placed.
the "-H" content is for the header
the "-d" is for the contents (body)
and for what its worth, the industry standard has been moving towards postman as a common chrome plugin/tool instead of advanced rest client, but to each their own.

How to PUT a json object with an array using curl

I have a series of data to enter into database. The user interface to enter the data isn't good for bulk entry, so I'm trying to formulate a command line equivalent. When I examine the network request of the UI in chrome, I see a PUT request of a json object. When I try to replicate the request
curl -H 'Accept: application/json' -X PUT '{"tags":["tag1","tag2"],"question":"Which band?","answers":[{"id":"a0","answer":"Answer1"},{"id":"a1","answer":"answer2"}]}' http://example.com/service`
I get a error
curl: (3) [globbing] nested braces not supported at pos X
Where X is the character position of first "[".
How can I PUT a json object that includes an array?
Your command line should have a -d/--data inserted before the string you want to send in the PUT, and you want to set the Content-Type and not Accept.
curl -H 'Content-Type: application/json' -X PUT -d '[JSON]' \
http://example.com/service
Using the exact JSON data from the question, the full command line would become:
curl -H 'Content-Type: application/json' -X PUT \
-d '{"tags":["tag1","tag2"],
"question":"Which band?",
"answers":[{"id":"a0","answer":"Answer1"},
{"id":"a1","answer":"answer2"}]}' \
http://example.com/service
Note: JSON data wrapped only for readability, not valid for curl request.
Although the original post had other issues (i.e. the missing "-d"), the error message is more generic.
curl: (3) [globbing] nested braces not supported at pos X
This is because curly braces {} and square brackets [] are special globbing characters in curl.
To turn this globbing off, use the "-g" option.
As an example, the following Solr facet query will fail without the "-g" to turn off curl globbing:
curl -g 'http://localhost:8983/solr/query?json.facet={x:{terms:"myfield"}}'
It should be mentioned that the Accept header tells the server something about what we are accepting back, whereas the relevant header in this context is Content-Type
It's often advisable to specify Content-Type as application/json when sending JSON. For curl the syntax is:
-H 'Content-Type: application/json'
So the complete curl command will be:
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{"tags":["tag1","tag2"],"question":"Which band?","answers":[{"id":"a0","answer":"Answer1"},{"id":"a1","answer":"answer2"}]}' http://example.com/service`
The only thing that helped is to use a file of JSON instead of json body text. Based on How to send file contents as body entity using cURL
Try using a single quote instead of double quotes along with -g
Following scenario worked for me
curl -g -d '{"collection":[{"NumberOfParcels":1,"Weight":1,"Length":1,"Width":1,"Height":1}]}" -H "Accept: application/json" -H "Content-Type: application/json" --user test#testmail.com:123456 -X POST https://yoururl.com
WITH
curl -g -d "{'collection':[{'NumberOfParcels':1,'Weight':1,'Length':1,'Width':1,'Height':1}]}" -H "Accept: application/json" -H "Content-Type: application/json" --user test#testmail.com:123456 -X POST https://yoururl.com
This especially resolved my error curl command error : bad url colon is first character