Console.Write(##teamcity[setParameter ...]) not working after Updating to 2022.10.1 (Solved)
We had a bit of an issue in office that meant we had to migrate our sever over to a new account. As part of that I reinstalled with the current version. Oddly our builds were failing because a path to the Unity editor couldn't be found at the location set as "%unityDirectory%/Hub/Editor/%unityVersion%/Editor/Unity.exe". The output of where his is used this was [step 7]:
Running unity build command "C:/Unity/Hub/Editor//Editor/Unity.exe"
You can see the double slash where that value should be. So I Checked where it was set [Step 5]:
string versionString = match.Groups[2].Value.Trim();
Console.Write($"Using Unity Version {versionString}");
Console.Write($"##teamcity[setParameter name='unityVersion' value='{versionString}']");
string unityDirectory = Args[0];
string unityEditorLocation = $"{unityDirectory}/Hub/Editor/{versionString}/Editor/Unity.exe";
if (File.Exists(unityEditorLocation))
{
Console.Write($"Unity Editor found at {unityEditorLocation}");
Console.Write($"##teamcity[setParameter name='unityEditorLocation' value='{unityEditorLocation}']");
}
the output of which is:
Using Unity Version 2021.3.11f1
Unity Editor found at C:/Unity/Hub/Editor/2021.3.11f1/Editor/Unity.exe
but checking the value of 'unityVersion' in a new test step directly after it's set via 'setParameter' shows that it's empty. setParameter does not show up in logs and has been working perfectly in this chain for over a year, right up until this morning when it was reinstalled. Any idea what might be up? and why this values seems to no longer be getting set?
(Edit, also, probably want to fix your forum's code block formatting UI in chrome, it's broken as hell)
Please sign in to leave a comment.
Hi! Please check how and when in the build you use the TeamCity configuration parameter
%unityVersion%.There is a limitation with the
##teamcity[setParameter ...]service message: the new parameter value will only be available in the subsequent build steps (documentation). If you try to reference the parameter in the same build step where you send the##teamcity[setParameter ...]service message, the parameter will still have the old value (or will be unset if there was no old value).Yeah, definitely aware of that limitation. This is a later step. The assignment happens in 4, I check in a completely new step (5) after to see if it's set and the error happens when it's actually used in step 7. So it absolutely isn't getting set, even in later steps.
Also worth noting that this exact code was working before we had to re-setup the server
It also only seems to be failing in c#, the other scripts are correctly setting the parameters
and with verbose logging on ##teamcity[setParameter name='changesetNumber' value='x'] shows up in the logs for command line (in light grey) but no logs shows up for the service message in c#. Other Console.Write on the other hand, show up just fine
I finally found it. The issue was
which somehow worked in the older version of the c# script (it probably shouldn't have). Switching it to the correct Console.WriteLine was the solution.