Trigger build with parameters - teamcity

Following a TC upgrade to 2018
My previous script of triggering a TC build with parameters is not working
The script we were using uses the following api:
https://[server]/httpAuth/action.html?add2Queue=[build name]&name=[param name]&value=[param value]
I'm trying to migrate to restApi
from (https://confluence.jetbrains.com/display/TCD18/REST+API#RESTAPI-QueuedBuilds):
I have tried
https://[server]/app/rest/buildQueue?locator=buildType:[build name],[param name]:[param value]
Currently I have 2 issues:
I get a build triggered successfully - but it has not been triggered
Documentation was not clear, how to I trigger the build with parameters ?
Can you please advise on how to trigger the build successfully with parameters (also could be more than 1)

Firstly you right TeamCity documentation is not clear. Respect to this link;
For triggering a build you must make POST request to this url and send buildType id through body.
http://localhost:8111/httpAuth/app/rest/buildQueue
Also you can pass configuration parameter into body.
XML body for trigger build with parameters:
<build><buildType id="YourBuildTypeId"/>
<properties><property name="PARAM1" value="VALUE1"/></properties>
</build>
JSON body for trigger build with parameters:
{
"buildType": {
"id": "YourBuildTypeId"
},
"properties": {
"property": [
{
"name": "PARAM1",
"value": "VALUE1"
},
{
"name": "PARAM2",
"value": "VALUE2"
}
]
}
}
You can use below curl script.
curl -X POST \
http://localhost:8111/httpAuth/app/rest/buildQueue \
-H 'Accept: application/json' \
-H 'Content-Type: application/xml' \
-d '<build><buildType id="YourBuildTypeId"/>
<properties><property name="PARAM1" value="VALUE1"/></properties>
</build>'

Related

Gerrit Checks plugin - How to create/update Checker for a gerrit change with API

My Gerrit server installed Checks plugin and I also try to create many checkers for my repo.
I can get information about Checkers of a gerrit change by admin account (configured Administrate Checkers and password was generated for "HTTP Credentials" in settings menu) with curl command:
url="http://my_gerrit_ip:8081"
curl -k -X GET \
-u admin:Jy7xK+oJ2tA2yzc+jG5n7yttsFUNmXDNKEDh+PoygQ \
--header "Content-Type: application/json; charset=UTF-8" \
--data gerrit-field-content.json \
$url/changes/66/revisions/1/checks/
The output looks like:
[
{
"repository": "test2",
"change_number": 66,
"patch_set_id": 1,
"checker_uuid": "a:a",
"state": "NOT_STARTED",
"created": "2020-10-28 02:56:55.000000000",
"updated": "2020-10-28 02:56:55.000000000",
"checker_name": "test2",
"checker_status": "ENABLED",
"blocking": [
"STATE_NOT_PASSING"
],
"submit_impact": {
"required": true
},
"checker_description": "test2"
},
{
"repository": "test2",
"change_number": 66,
"patch_set_id": 1,
"checker_uuid": "b:b",
"state": "NOT_STARTED",
"created": "2020-10-28 02:56:55.000000000",
"updated": "2020-10-28 02:56:55.000000000",
"checker_name": "test2_2",
"checker_status": "ENABLED",
"blocking": [],
"submit_impact": {},
"checker_description": "test2_2"
}
]
But now, i want to update the state of a Checker of my gerrit change via curl command too but it throw message "Authentication required".
I tried with:
curl -k -X POST \
-u admin:Jy7xK+oJ2tA2yzc+jG5n7yttsFUNmXDNKEDh+PoygQ \
--header "Content-Type: application/json; charset=UTF-8" \
--data gerrit-field-content.json \
$url/changes/66/revisions/1/checks/
The gerrit-field-content.json content:
{
"checker_uuid": "a:a",
"state": "SUCCESSFUL",
"url": "",
"started": ""
}
How can I update state of a checker via api? Or are there any better way to do this?
Result of checker state maybe look like a sample in this one https://gerrit-review.googlesource.com/c/gerrit/+/285580
Note: the it's not able update checker when i leave password for admin empty (curl -u admin:) because my Gerrit server is not require password for logging in.
Afraid I am just poking around myself, but in the zuul change it says:
* Access control for the `checks` API in Gerrit depends on a single
global administrative permission, ``administrateCheckers``. This is
required in order to use the `checks` API and can not be restricted
by project. This means that any system using the `checks` API can
interfere with any other.
Hope that is helpful, as I deploy this I'll update if I gain any other useful experience

Send request to elastic watcher via curl

ELK 7.X
I am trying to create elastic search watcher with curl using the input file. Something like this
curl -X PUT _watcher/watch/cluster_health_watch --data-binary #inputFile
1) What is the file type to be used ? Most of the data is json, but in "actions" field when sending an email, the email body can be HTML !
2) Is there any way that the HTML in the body can be referred from an external file, such that input file can be json ?
Just escaped the double quotes in the html string by adding "\".
Ex:-
<h3 style=\"color:red\"></h3>
"actions": {
"send_email": {
"email": {
"to": "xxxx#gmail.com",
"subject": "My Subject",
"body": {
"html": "<h3 style=\"color:red\"> There was a problem</h3>"
}
}
}
}
curl -X PUT _watcher/watch/cluster_health_watch -H 'Content-Type: application/json' --data-binary #inputFile.json

How to read response of a JIRA REST API

Using the Atlassian documentation, I'm able to create a new JIRA ticket using curl command. I want to understand how to read the response of this command into a variable? Essentially i want to store the JIRA ticket ID into a variable that can be used in other scripts.
Reference Link: https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/
_SAMPLE_CODE_
curl -D- -u charlie:charlie -X POST --data '{
"fields": {
"project":{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/
_SAMPLE_RESPONSE_
{
"id":"39000",
"key":"TEST-101",
"self":"http://localhost:8080/rest/api/2/issue/39000"
}
From the above log, I want to understand how can we fetch the "key" (i.e. JIRA number or JIRA ID) from response (essentially stdout) into a variable.
you can use jq command line tool to extract value from json:
#!/bin/bash
key=$(curl -s -u charlie:charlie -X POST --data '{
"fields": {
"project":{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/|jq -r .key)
echo "key: $key"
jq command is not installed by default on linux systems.
you will need to install it manually:
sudo apt install jq
sudo yum install jq

how to get list of flowfile from queue in nifi connection?

I want to get each flowfile from queue in connection when the flow was blocked with NiFi REST API.
I find that the functions of /nifi-api/flowfile-queues/{id}/listing-requests can meet my needs.And it response a ListingRequestDTO:
enter image description here
The field named flowFileSummaries can return a array of flowFile.And then I can get each uuid from flowfiles:
{
"uri": "value",
"uuid": "value",
"filename": "value",
"position": 0,
"size": 0,
"queuedDuration": 0,
"lineageDuration": 0,
"clusterNodeId": "value",
"clusterNodeAddress": "value",
"penalized": true
}
BUT,when I use the API and can not find the "FlowFileSummary"
{
"listingRequest": {
"id": "0165122a-e1ac-134e-2c09-92ba9ca93e8b",
"uri": "http://.../nifi-api/flowfile-queues/07a23828-d6f3-1e00-27af-f0428a493507/listing-requests/0165122a-e1ac-134e-2c09-92ba9ca93e8b",
"submissionTime": "09/07/2018 18:46:57.496 CST",
"lastUpdated": "18:46:57 CST",
"percentCompleted": 0,
"finished": false,
"maxResults": 100,
"state": "Waiting for other queue requests to complete",
"queueSize": {
"byteCount": 370689,
"objectCount": 995
},
"sourceRunning": false,
"destinationRunning": false
}
}
So, is there any possible solution to achieve? or any other solution? Thanks!
I don't believe the flow file summaries are available until the listing request is complete. In your example response above, note that finished is false. You can keep querying the API for that listing request until finished is true, then the summaries should be available. Then you can use the /flowfile-queues/{id}/flowfiles/{flowfile-uuid} and /flowfile-queues/{id}/flowfiles/{flowfile-uuid}/content endpoints to get the attributes and content of each flow file.
You do not need to have the listing request to complete. Here are the steps I used successfully to get the contents of flow file
Get the id of the Queue from NiFi UI console
Replace id here : curl -X POST https://myhost:443/nifi-api/flowfile-queues/{id}/listing-requests -H 'Authorization: Bearer ' --compressed --insecure
To get uris of flowfiles in the queue, get the value of 'uri' field from the response of the command in step2 and use it in next curl command, for ex:
For ex: curl -X GET https://myhost:443/nifi-api/flowfile-queues/0f66c88c-225d-3229-b2e1-597d8fba2c09/listing-requests/13802f9c-016a-1000-0000-00004eb033fb -H 'Authorization: Bearer ' --compressed --insecure
To get flow file content, get the value of 'uri' field from the response of the command in step3 and and use it in next curl command, for ex:
curl -X GET https://myhost:443/nifi-api/flowfile-queues/0f66c88c-225d-3229-b2e1-597d8fba2c09/flowfiles/7ccf5c54-7c8d-448a-a124-7f75f5845ec1?clusterNodeId=35a3df65-d7bf-47d2-b162-ea15c3c02c30 -H 'Authorization: ' --compressed --insecure
Note: if there are multiple flow files, you will see see multiple URIs in the response of step 3 curl command

How to update couchbase lite view with Rest API?

How to update couchbase lite view with Rest API ?
From Rest API how to tell indexer that view is updated . I have tried the below code but it did not work.It still returns the old index.
What is the correct way of telling indexer that view is updated so that it can recreate the index.
'PUT'
{db}/_design/todo
{
"_rev":"hf675757577hhfh",
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
//My view create request was like below:
{db}/_design/todo
{
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
It looks like you may just have some formatting problems. This shows how to do what you're trying from the command line:
curl -X PUT 'http://localhost:4985/db/_design/todo' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "_rev": "hf675757577hhfh", "views": { "list": { "map": "function(doc) { if (doc.type == \"list\") { emit(doc._id, { \"name\": doc.name }); }}"}}}'
You can test your results with this command:
curl -X GET 'http://localhost:4985/db/_design/todo/_view/list'
You may want to refer to the documentation, which has more examples, at https://developer.couchbase.com/documentation/mobile/current/guides/sync-gateway/views/index.html

Resources