Setting agent requirements using REST

Is it possible to set a builds agent requirements using the rest API.

I can retrievie them but a post xml request doesn't seem to be supported.

11 comments
Comment actions Permalink

Hi

> doesn't seem to be supported.
It should. Can you explain that in detail?

0
Comment actions Permalink

If a post  back the xml that I receive from the get request I  get an Internal server error.

Looking at the API page what should the <id> be used for?  At the monent I am not setting it to anything.  This is ok for the get request.  I presume it a post to change settings?

http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements/<id>

0
Comment actions Permalink

> I  get an Internal server error.
Exact error message and related logging form the teamcity-reslt.log would help a bit in analyzing this.

> At the monent I am not setting it to anything.
Do you mean you post to ".../agent-requirements/<id>" ?
That is not correct.

The page implies that:

Build configuration agent requirements: GET/DELETE http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements/<agent_requirement_id>
Create build configuration agent requirement: POST http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements The XML posted is the same as retrieved by GET request


So you should POST to ".../agent-requirements/"

0
Comment actions Permalink

Sorry I can't easily provide logs as the server doesn't have internet access and we are not allowed to transfer outside of internal network without authorisation.

I send a get request to

httpAuth/app/rest/buildTypes/id:bt1222/agent-requirements

this returns the full xml of the agent requirments


I want to then use the same agent requirement on a different build so I post to

httpAuth/app/rest/buildTypes/id:bt1224/agent-requirements

but get a 500: Internal server error response.

- java.lang.IllegalArgumentException



What is the <agent_requirement_id> that you speak of?

How do I turn on rest log files?

0
Comment actions Permalink

btw, I'm looking at this page

http://confluence.jetbrains.net/display/TW/REST+API+Plugin

Which states:

Features, triggers, agent requirements, artifact and snapshot dependencies follow the same pattern as steps with URLs like:
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/features/<id>
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/triggers/<id>
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements/<id>
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/artifact-dependencies/<id>
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/snapshot-dependencies/<id>

What does the <id> refer to?

and what is allowed in term of GET/DELETE/PUT/POST.  This isn't at all clear.

0
Comment actions Permalink

Hi,

> How do I turn on rest log files?

Have you looked into logs\teamcity-reslt.log ? Should be ON by default.

> What does the <id> refer to?

To the id of the item you want to get or delete. If you look into XML repurend by http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator> that should be pretty much clear.



> and what is allowed in term of GET/DELETE/PUT/POST.  This isn't at all clear.

Seems, I already replied to that earlier:
>>Build configuration agent requirements: GET/DELETE http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements/<agent_requirement_id>
>>Create build configuration agent requirement: POST http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements The XML posted is the same as retrieved by GET request

>> So you should POST to ".../agent-requirements/"

If that is still not clear, try these curl commands:

curl -v --user username:password http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements/<id> -o out.xml
where <id> you can infer from XML retrieved by http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator> request in <agent-requirement id="<id>"  ...> node.
Then edit out.xml to change <property name="property-name" value="<name>"> node to have another "<name>".
Then execute:
curl -v --user username:password POST http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/agent-requirements -d @out.xml --header "Content-Type: application/xml"

0
Comment actions Permalink

It seems my problem is due to a template configuration having the agent definition.  If I try to change the agent for the build that inherits from the template I get an error  'requirement for parameter with name 'projectTypes'  already exists.'  If I detatch it from the template then is works.


Note that I can change this the GUI with no issues.

0
Comment actions Permalink

Thank you for the details.
Inability to override agent requirement will be fixed in next release: TW-23427

0
Comment actions Permalink

Hi Yegor. I`m still experiencing this issue.
I`m trying to POST an Agent requirement via REST, it gives me 400 Bad request.
I tried this with a build associated with template and also when it was detached from the template. Same result (400).
My TC version is 9.0.3
In the REST log I see :
Error has occurred during request processing (Bad Request). Error:
jetbrains.buildServer.server.rest.errors.BadRequestException: Requirement for parameter with name 'env.hosted.environments' already exists. Invalid request. Please check the request URL and data are correct. Request: POST '/httpAuth/app/rest/buildTypes/id:MySolutionsAppstore_88SmokeTestPoC_FxSO_PostDeploymentSmokeTests/agent-requirements', from client ####, user-agent null, authenticated as #### {id=1}.

0
Comment actions Permalink

Hi Yegor.
Update : I`m able to use PUT and DELETE directly for the ../agent-requirements/<requirement-id> - which is something I can work with.
This might be updated in the documentation as it is not very clear.
Thanks.

0
Comment actions Permalink

If someone faced with alike problem, please see how it was resolved.

0

Please sign in to leave a comment.