How to pass a parameter to a trigger

Completed

I need to add a build(say build B) as a trigger within another build(say build A). Now build B should only be triggered from build A if the parameter 'isTriggerRequired' within build A is set as true. So please let me know how can I achieve this?

Also I am new in teamcity, so can you please explain the solution in some detail with example(s)

0
3 comments

Hello,

As of now it is not possible to trigger a build basing on some parameter out of the other build context. What you could do, though, is to start (or to not start) a build via custom command line script step which would call TeamCity REST API (https://www.jetbrains.com/help/teamcity/rest-api.html). For example, you could have a script which would invoke a below REST API call:

[POST] <TeamCity URL>/app/rest/buildQueue

<build> <buildType id="buildConfID"/> </build>

(where buildConfID is the ID of configuration you need to trigger). You may control whether the request is made or not within the script, or you can use conditional build steps feature (https://blog.jetbrains.com/teamcity/2020/07/new-in-2020-1-conditional-build-steps/). 

I hope this helps.

1

Hi RG. If I understood your use case correctly, you need to run build A, and if if the parameter 'isTriggerRequired' is set to true, trigger build B from build A.

To do that:

1. Add a step to build A which runs a script that sending a POST request to http://teamcity:8111/app/rest/buildQueue to trigger a build via REST API based. Here's an example in PowerShell of such a script:

$buildConfigurationId = "MyCoolProject_BuildB"
$branchName = "master"
$uri = "http://teamcity:8111/app/rest/buildQueue"
$token = "XXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

[xml]$payload = @'
<build personal="false" branchName="">
<buildType id=""/>
<comment><text>Optional comment text</text></comment>
</build>
'@
$payload.build.branchName = $branchName
$payload.build.buildType.id = $buildConfigurationId
$payload
$headers = @{"Authorization" = "Bearer $token"}
$contentType = "application/xml"
Invoke-RestMethod -Method POST -Uri $uri -ContentType $contentType -Headers $headers -Body $payload

2. In the build step settings add a condition: "isTriggerRequired equals true".

3. Replace the $buildConfigurationId, $branchName, $uri, and $token with the actual values.

Is that what you were looking for?

2

Hi Antoly

 

Yes this is exactly what I want. Thanks!!!

0

Please sign in to leave a comment.