Immutable solution version
TeamCity: pass a value from one build step to the next with a service message
Complete solution
From your step 3 script, print this exact line to stdout: ##teamcity[setParameter name='env.PASSED_ID' value='the-id-here'].
From your step 3 script, print this exact line to stdout: ##teamcity[setParameter name='env.PASSED_ID' value='the-id-here'] . TeamCity picks it up and the value is available as an env var in step 4 and later. Three gotchas the thread calls out: the parameter only becomes available in the NEXT step, never the one that sets it; the line must go to stdout with no extra formatting or quoting around it; and if the value contains spaces or quotes, escape them per the service-message rules or the parse silently breaks.
Context: Stack Overflow #8219493 (accepted answer, 77 votes): a build generates an id in step 3 that step 4 needs. Setting an env var in the step 3 script does not carry over, because each build step runs its own process. The accepted answer points to TeamCity's service messages: the script prints a specially formatted line to stdout and TeamCity turns it into a build parameter for the following steps.
Evidence
Source: Stack Overflow #8219493 (accepted answer, 77 votes): a build generates an id in step 3 that step 4 needs. Setting an env var in the step 3 script does not carry over, because each build step runs its own process. The accepted answer points to TeamCity's service messages: the script prints a specially formatted line to stdout and TeamCity turns it into a build parameter for the following steps.
Verified resolution: From your step 3 script, print this exact line to stdout: ##teamcity[setParameter name='env.PASSED_ID' value='the-id-here'] . TeamCity picks it up and the value is available as an env var in step 4 and later. Three gotchas the thread calls out: the parameter only becomes available in the NEXT step, never the one that sets it; the line must go to stdout with no extra formatting or quoting around it; and if the value contains spaces or quotes, escape them per the service-message rules or the parse silently breaks.
Source URL: https://stackoverflow.com/questions/8219493/teamcity-passing-an-id-generated-in-one-build-step-to-a-later-build-step
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_BxHaTwSWG6BVDUqcG47O4Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">TeamCity: pass a value from one build step to the next with a service message <span>— Vectle</span></a>