set parameter with python script
I have a python script which finds an account alias, which then gets stored as variable decomaccountalias
I have a env.variable in teamcity called env.DECOM_ACCOUNT_ALIAS, and i want to set the variable in my python script (decomaccountalias) to that to utilise in the next build step
My code for doing that
print(f"Setting env.DECOM_ACCOUNT_ALIAS={decomaccountalias}")
print(f"##teamcity[setParameter name='env.DECOM_ACCOUNT_ALIAS' value='{decomaccountalias}']")
the build repsonds with
##teamcity[setParameter name='env.DECOM_ACCOUNT_ALIAS' value='['test-account']
error while parsing TeamCity service message: property value not found (no "=" sign). Valid service message has a form of "##teamcity{messageName name1='escaped_value' etc etc
i did try and escape the values but never worked either
print(f"##teamcity|[setParameter name=|'env.DECOM_ACCOUNT_ALIAS|' value=|'{decomaccountalias}|'|]")
Any help would be greatly appreciated
Thank you
Please sign in to leave a comment.
Update - When i added in the escaped characers the error message did dissapear
However it's still not setting the env.DECOM_ACCOUNT_ALIAS
build returned
##teamcity|[setParameter name=|'env.DECOM_ACCOUNT_ALIAS|' value=|'['test-account']'|]
Hi,
What version of Python are you using? I tried to replicate your issue using Python 3.8.5, but it works as expected. I have a Python build step that runs a simple script of the following:
I have another Python build step that issues this single command:
In the build log, I can see the value of env.DECOM_ACCOUNT_ALIAS has been set to "asdfasdf" in the second step.
Hi. It looks like you are escaping square brackets and single quotes in the entire service message. They only need to be escaped in the value parts of the service message. I marked them as XXXX and YYYY in this example:
You can try something like this:
https://www.jetbrains.com/help/teamcity/service-messages.html#Escaped+Values
Cheers,
Anatoly
Okay, I think I just realized that you're setting decomaccountalias = "['test-account']". If I include the brackets, I am able to reproduce your issue as this seems to be messing with the service message format. I escaped the `, [, and ] characters and it works then:
One way to resolve this would be to include a slice of the decomaccountalias variable in the service message and add the ', [ , and ] characters back in like this: