0

I am working on a C# tool to trigger build with the REST API of TeamCity. I want to trigger build with specific vcs number, so here's what I'm doing:

POST => teamcity-server/httpAuth/app/rest/buildQueue 
HEADER => basicAuthCredentials
BODY => 

<build>
    <buildType id="SomeValidBuildId"/>
    <properties>
        <property name="SAMPLE_TEST" value="VERY_TESTY"/>
    </properties>
    <lastChanges>
        <change locator="version:4354174,buildType:(id:SomeValidBuildId)" />
    </lastChanges>
</build>

The request is working, the build has my properties and my specified vcs number. Everything is fine, except when there was no previous build associated to that vcs number, the request fails and show this error message:

Http request failed: 
error : Responding with error, status code: 404 (Not Found).
error : Details: jetbrains.buildServer.server.rest.errors.NotFoundException: Nothing is 
found by locator 'version:4354174,buildType:(id:SomeValidBuildId),count:1'.
error : Could not find the entity requested. Check the reference is correct and the user has permissions to access the entity.

The build has access to VcsRoot settings, and everything it needs, how do can I trigger custom build on vcs number that were never built before?

MathieuAuclair
  • 1,229
  • 11
  • 41

2 Answers2

2

You get error response when the change with the passed version is not yet detected by TeamCity and so far TeamCity need to detect the change before it can be used in a build. You can configure commit/push hooks to let TeamCity know about the change as soon as it occurs or invoke the commit hook URL before trying to trigger the build. There still can be some delay between the reception of the commit hook request and the change being detected (typically seconds), so it makes sense to wait for some time and only then trigger the build.

Yaegor
  • 1,771
  • 9
  • 12
  • Well we are using the perforce extension and we took a pending changelist from TeamCity that was never been built before, so it was already in TeamCity?! :/ – MathieuAuclair Sep 19 '19 at 14:09
1

This was against vcs perforce, running curl from windows cmd line, and allows me to trigger TeamCity builds on a given p4 branch and change list

curl -u "teamcityUser:teamcityPassword" -X POST -d "{
""buildType"": {""id"": ""teamcityProjectId""},
""branchName"":""//p4/branch"",
""revisions"": {""revision"":[{
""version"":""59933"",
""vcsBranchName"":""//p4/branch""
}]}
}" --header "Content-Type: application/json" -H "Accept: application/json" <TeamCity Server host>:<port>/httpAuth/app/rest/buildQueue
DavidCoen
  • 26
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 08:35