Create snapshot dependency using REST

 I'm assuming a typical simple snapshot dependency scenario where build config B is snapshot-dependent on build config A, so when I execute B, A will build first while B will be on queue. Here's my call to the REST endpoint using curl

curl -v -u user:password http://localhost:81/app/rest/buildTypes/id:<id_build_B>/snapshot-dependencies --request POST --header "Content-Type:application/xml" --data @C:\snapshot-dependency.xml

This is the content of the request to post. Getting a 400 (bad request) due to this SAXParseException - premature end of file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<snapshot-dependency type="snapshot_dependency">
     <properties count="5">
       <property name="run-build-if-dependency-failed" value="RUN_ADD_PROBLEM"/>
       <property name="run-build-if-dependency-failed-to-start" value="MAKE_FAILED_TO_START"/>
       <property name="run-build-on-the-same-agent" value="false"/>
       <property name="take-started-build-with-same-revisions" value="false"/>
       <property name="take-successful-builds-only" value="false"/>
     </properties>
     <source-buildType id="id_build_A"
                       name="Build_A"
                       projectName="Project_A"
                       projectId="id_project_A"
                       href="/app/rest/buildTypes/id:id_build_A"
                       webUrl="http://localhost:81/viewType.html?buildTypeId=id_build_A"/>
</snapshot-dependency>

This may not be the exact xml response (It was suggested in another post) you would receive when you would get the snapshot dependencies in build B after adding the snapshot dependency to A using the call below.

curl -v -u user:password http://localhost:81/app/rest/buildTypes/id:<id_build_B>/snapshot-dependencies

I tried with that as well and it didn't work. So I basically took the root 'snapshot-dependencies' element out and also took out the ID attribute of the 'snapshot-dependency' element. The reason I did that is because I have a Python script that uses that xml request form to successfully add dependency using the Requests library. I

Please comment as to which one is the correct xml.

0
1 comment

I've been trying to look at the xml but it looks fine on my side. Your initial request should work as far as I can tell.

 

You can definitely drop the "href" and "webUrl" parameters from the "source-buildType", they're helpers to create links. If it's more comfortable with Python, you might also want to try JSON requests instead of XML. It might have something to do with the transfer, so being able to debug what exactly curl is sending might indicate whether there is any trouble with the encoding or loading of the file from the root of the C drive.

0

Please sign in to leave a comment.