如何通过具有特定vcs编号的teamcity从REST API正确触发构建?

时间:2019-09-18 18:09:47

标签: teamcity teamcity-rest-api

我正在使用C#工具触发TeamCity的REST API的构建。我想使用特定的vcs编号触发构建,所以这是我正在做的事情:

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>

该请求正在运行,该构建具有我的属性和我指定的vcs编号。一切都很好,除非没有与该vcs编号相关的先前版本,该请求将失败并显示以下错误消息:

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.

该版本可以访问VcsRoot设置及其所需的所有内容,如何在从未建立过的vcs编号上触发自定义生成?

1 个答案:

答案 0 :(得分:1)

当TeamCity尚未检测到所传递版本的更改,并且so far TeamCity需要检测到更改才能在构建中使用它时,您会收到错误响应。您可以configure commit/push hooks在发生更改后立即让TeamCity知道更改,或者在尝试触发构建之前调用提交挂钩URL。在接收到提交挂钩请求和检测到更改之间仍然存在一定的延迟(通常为几秒钟),因此等待一段时间然后才触发构建是有意义的。