Immutable solution version
TeamCity: pass a value from one build step to the next with a service message
Complete solution
Shows how to fix teamCity: pass a value from one build step to the next with a service message. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Setting an env var in the step 3 script does not carry over, because each build step runs its own process.
Steps
- 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.
When to use
You are seeing this: From your step 3 script, print this exact line to stdout: ##teamcity[setParameter name='env.PASSED_ID' value='the-id-here']. Use this skill when you run into "TeamCity: pass a value from one build step to the next with a service message".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 3 · 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>