Rest API: running a 'custom build' with a given set of artifact dependencies

Teamcity version: 8.1.1

Hi guys,

Is it currently possible to trigger a build via the REST API that has a given set of artifact dependencies?

I noticed that when GETing a build via the API, there is an artifact-dependencies element, which I thought you might be able to post back with a set "number" - but it seems to be ignored by TeamCity.

If not, are there any plans to integrate this into a future version of TeamCity?

All the best,
Paul

10 comments
Comment actions Permalink

Just for more information, I was hoping to POST the following, in JSON to http://tango.ci.ttldev/httpAuth/app/rest/buildQueue

"buildType": {
        "id": "..."
    },
    "custom-artifact-dependencies": {
        "artifact-dependency": [
            { .. }
        ]
    }

0
Comment actions Permalink

Paul,

passing "custom-artifact-dependencies" when triggering a build should set them in the build triggered.
The basic idea here is to trigger a build manully via custom run build dialog, then get the build detials via REST and post the details back to /app/rest/buildQueue - the same build should be queued.

If this does not seem like the case for you, please detail the full request body sent, the response received, the details of the builds set as artifact dependencies, the settings of the build type of the build as well as teamcity-server.log and teamcity-rest.log

0
Comment actions Permalink

Yegor,

Thanks for the reply. Following your instructions, I'm getting the build details by querying a custom build (with custom artifact deps) by ID:

GET http://<removed>/httpAuth/app/rest/builds/id:5833, returns:

{
    "id": 5833,
    "buildTypeId": "DeploymentE35_E35GreenDeploymentMap",
    "number": "4.14.772.green.26",
    "status": "SUCCESS",
    "state": "finished",
    "href": "/httpAuth/app/rest/builds/id:5833",
    "webUrl": "http://<removed>/viewLog.html?buildId=5833&buildTypeId=DeploymentE35_E35GreenDeploymentMap",
    "statusText": "Success",
    "buildType": {
        "id": "DeploymentE35_E35GreenDeploymentMap",
        "name": "E35 Green Deployment Map",
        "projectName": "Deployment-E35",
        "projectId": "DeploymentE35",
        "href": "/httpAuth/app/rest/buildTypes/id:DeploymentE35_E35GreenDeploymentMap",
        "webUrl": "http://<removed>/viewType.html?buildTypeId=DeploymentE35_E35GreenDeploymentMap"
    },
    "tags": {
        "tag": []
    },
    "queuedDate": "20140519T135336+0100",
    "startDate": "20140519T135338+0100",
    "finishDate": "20140519T135702+0100",
    "triggered": {
        "type": "user",
        "date": "20140519T135336+0100",
        "user": {
            "username": "paulk",
            "name": "Paul Kiddie",
            "id": 7,
            "href": "/httpAuth/app/rest/users/id:7"
        }
    },
    "lastChanges": {
        "count": 1,
        "change": [
            {
                "id": 12517,
                "version": "de2adc4016e5595b71ada5549e590ca323f99272",
                "username": "murali.mani",
                "date": "20140516T082751+0100",
                "href": "/httpAuth/app/rest/changes/id:12517",
                "webLink": "http://<removed>/viewModification.html?modId=12517&personal=false"
            }
        ]
    },
    "changes": {
        "href": "/httpAuth/app/rest/changes?locator=build:(id:5833)"
    },
    "revisions": {
        "revision": [
            {
                "version": "12926e50f68d8f70b1bbe88890403f81171a740d",
                "vcs-root-instance": {
                    "id": "68",
                    "vcs-root-id": "Root_CodeTtldevTabletWeb",
                    "name": "code.ttldev:TabletWeb",
                    "href": "/httpAuth/app/rest/vcs-root-instances/id:68"
                }
            },
            {
                "version": "de2adc4016e5595b71ada5549e590ca323f99272",
                "vcs-root-instance": {
                    "id": "90",
                    "vcs-root-id": "CodeTtldevConfigType2",
                    "name": "code.ttldev:configType2",
                    "href": "/httpAuth/app/rest/vcs-root-instances/id:90"
                }
            }
        ]
    },
    "agent": {
        "id": 28,
        "name": "ip_10.41.9.25",
        "typeId": 28,
        "href": "/httpAuth/app/rest/agents/id:28"
    },
    "artifacts": {
        "href": "/httpAuth/app/rest/builds/id:5833/artifacts/children"
    },
    "relatedIssues": {
        "href": "/httpAuth/app/rest/builds/id:5833/relatedIssues"
    },
    "properties": {
        "count": 9,
        "property": []
    },
    "statistics": {
        "href": "/httpAuth/app/rest/builds/id:5833/statistics"
    },
    "artifact-dependencies": {
        "count": 2,
        "build": [
            {
                "id": 5813,
                "buildTypeId": "ContentServer_Build",
                "number": "4.14.274",
                "status": "SUCCESS",
                "state": "finished",
                "branchName": "4.14",
                "href": "/httpAuth/app/rest/builds/id:5813",
                "webUrl": "http://<removed>/viewLog.html?buildId=5813&buildTypeId=ContentServer_Build"
            },
            {
                "id": 5716,
                "buildTypeId": "TabletWeb_Build",
                "number": "4.14.772",
                "status": "SUCCESS",
                "state": "finished",
                "branchName": "4.14",
                "href": "/httpAuth/app/rest/builds/id:5716",
                "webUrl": "http://<removed>/viewLog.html?buildId=5716&buildTypeId=TabletWeb_Build"
            }
        ]
    }
}

I then POST this body back to POST http://<removed>/httpAuth/app/rest/buildQueue with content-type and accept headers set to application/json mimetype

{
    "taskId": 8771,
    "buildTypeId": "DeploymentE35_E35GreenDeploymentMap",
    "state": "queued",
    "href": "/httpAuth/app/rest/buildQueue/taskId:8771",
    "webUrl": "http://<removed>/viewQueued.html?itemId=8771:0:28",
    "buildType": {
        "id": "DeploymentE35_E35GreenDeploymentMap",
        "name": "E35 Green Deployment Map",
        "projectName": "Deployment-E35",
        "projectId": "DeploymentE35",
        "href": "/httpAuth/app/rest/buildTypes/id:DeploymentE35_E35GreenDeploymentMap",
        "webUrl": "http://lonbti-tcsvr01v/viewType.html?buildTypeId=DeploymentE35_E35GreenDeploymentMap"
    },
    "queuedDate": "20140519T140633+0100",
    "triggered": {
        "type": "user",
        "date": "20140519T140633+0100",
        "user": {
            "username": "paulk",
            "name": "Paul Kiddie",
            "id": 7,
            "href": "/httpAuth/app/rest/users/id:7"
        }
    },
    "lastChanges": {
        "count": 1,
        "change": [
            {
                "id": 12517,
                "version": "de2adc4016e5595b71ada5549e590ca323f99272",
                "username": "murali.mani",
                "date": "20140516T082751+0100",
                "href": "/httpAuth/app/rest/changes/id:12517",
                "webLink": "http://<removed>/viewModification.html?modId=12517&personal=false"
            }
        ]
    },
    "changes": {
        "href": "/httpAuth/app/rest/changes?locator=taskId:8771"
    },
    "revisions": {
        "revision": [
            {
                "version": "12926e50f68d8f70b1bbe88890403f81171a740d",
                "vcs-root-instance": {
                    "id": "68",
                    "vcs-root-id": "Root_CodeTtldevTabletWeb",
                    "name": "code.ttldev:TabletWeb",
                    "href": "/httpAuth/app/rest/vcs-root-instances/id:68"
                }
            },
            {
                "version": "de2adc4016e5595b71ada5549e590ca323f99272",
                "vcs-root-instance": {
                    "id": "90",
                    "vcs-root-id": "CodeTtldevConfigType2",
                    "name": "code.ttldev:configType2",
                    "href": "/httpAuth/app/rest/vcs-root-instances/id:90"
                }
            }
        ]
    },
    "agent": {
        "id": 28,
        "name": "ip_10.41.9.25",
        "typeId": 28,
        "href": "/httpAuth/app/rest/agents/id:28"
    },
    "compatibleAgents": {
        "href": "/httpAuth/app/rest/buildQueue/taskId:8771/compatibleAgents"
    },
    "properties": {
        "count": 9,
        "property": []
    },
    "custom-artifact-dependencies": {
        "artifact-dependency": []
    }
}

Note that custom-artifact-dependencies is empty, but I would have expected it to contain the elements from the 'artifact-dependencies' GET request. Am I understanding this correctly?

Thanks,
Paul

0
Comment actions Permalink

Paul,

For the dependnecies to be processed, there should be "custom-artifact-dependencies" node in the data posted when queuing a build. A note: "custom-artifact-dependencies" i not the same as "artifact-dependencies", it has "artifact-dependency" nodes under it, not "build".

The node will be added once you start a build via custom run build dialog with custom dependencies set manually on "Dependencies" tab.

0
Comment actions Permalink

Hi Yegor,

The JSON from GET http://<removed>/httpAuth/app/rest/builds/id:5833 is the result of running a custom build with custom dependencies set via the 'Dependencies' tab on the TC front end (see attached), and yet I'm not seeing this node.

Does it matter that they are not snapshop dependencies - rather they are artifact dependencies in the build configuration.

How should a custom-artifact-dependencies node look like?

Thanks for your help!
Paul



Attachment(s):
deps.PNG
0
Comment actions Permalink

Paul,

At this time "custom-artifact-dependencies" is present only for the queued builds - so you can query the build while still in the queue.

The node looks like:

  "custom-artifact-dependencies" : {
    "count" : 1,
    "artifact-dependency" : [ {
      "id" : "0",
      "type" : "artifact_dependency",
      "properties" : {
        "property" : [ {
          "name" : "cleanDestinationDirectory",
          "value" : "false"
        }, {
          "name" : "pathRules",
          "value" : "**.txt=>txt\n**.java=>java"
        }, {
          "name" : "revisionName",
          "value" : "buildId"
        }, {
          "name" : "revisionValue",
          "value" : "26054.tcbuildid"
        } ]
      },
      "source-buildType" : {
        "id" : "bt870"
      }
    }
}

0
Comment actions Permalink

Yegor,

That's great. I had to disable an agent to get the build to queue but worked like a charm when I did :)

I might suggest a feature request so that custom-artifact-dependancies can be grabbed at any point through the builds life.

One other thing to note, the custom build is using the build number from one of the artifacts to construct the overall version number, e.g. %dep.TabletWeb_Build.build.number%.%build.counter%, thus I found posting back the exact JSON from http://<removed>/httpAuth/app/rest/buildQueue/taskId:8793 was not sufficient to get the build to succeed.

I had to manually tweak artifact's revisionValue to be a version number, rather than a tcbuildid, e.g. "value": "5716.tcbuildid" => "value": "4.14.779"

Thanks for your help!

Paul

0
Comment actions Permalink

Hi Yegor,

Lets say my build has two artifact dependancies.

How would I set one to 'auto' (i.e. the last successful build) as in the TC custom build UI, whilst specifying a revisionValue for the other via the REST API?

Thanks,
Paul

0
Comment actions Permalink

Paul,

I apologize for the delayed reply.

> I found posting back the exact JSON from http://<removed>/httpAuth/app/rest/buildQueue/taskId:8793 was not sufficient to get the build to succeed.
> I  had to manually tweak artifact's revisionValue to be a version number,  rather than a tcbuildid, e.g. "value": "5716.tcbuildid" => "value":  "4.14.779"

Thank you for noting. I have reproduced the case and filed it as http://youtrack.jetbrains.com/issue/TW-36791


> How would I set one to 'auto' (i.e. the last successful build) as in the  TC custom build UI, whilst specifying a revisionValue for the other via  the REST API?

A good question.
One way it to calcualte the necessary builds in the script and set them by build number.
I will try to look ito this when time permits.

0
Comment actions Permalink

Just in case this is still relevant.
On how to trigger a build with artifact dependencies as if set to "auto" in the run custom build dialog:

You would need to post all the required dependnecies in "customBuildArtifactDependencies" node.
To ease that, you can get the dependnecies from the build configuration via /app/rest/buildTypes/XXX/artifact-dependencies request and then paste the content of the "artifact-dependencies" node into the "custom-artifact-dependencies" node of the build node, make the necessary changes and submit the node to the build queue.

0

Please sign in to leave a comment.