TeamCity - using setParameter to pass information between build steps

时光总嘲笑我的痴心妄想 提交于 2019-11-28 20:09:41

问题


I must be doing something differently than what was asked and answered here because the solution does not appear to be working for me: TeamCity, passing an id generated in one build step to a later build step

I want use a string generated by one build step in a final build step. So far I have set up an environmental variable called "TEST" that is empty. Both build steps use the Command Line Runner.

Build Step #1:

\##teamcity[setParameter name='env.TEST' value='test']

Build Step #2:

echo $TEST

echo %env.TEST%;

Placeholder for now, but if I could access the test string ('test') set in Build Step 1 I would be so happy.


回答1:


you need to echo that string, e.g.

echo "##teamcity[setParameter name='env.TEST' value='test']"



回答2:


What I found is that with long values, as soon as TeamCity is breaking down the log output into two separate lines echo will not work anymore - you have to use Write-Host instead.

Write-Host "##teamcity[setParameter name='env.TEST' value='test']"

This should always work, just a side note - this value will be available only on subsequent build steps.




回答3:


I think you have an extra "\" in there. Try removing that and add double quotes around it and it should work.

 "##teamcity[setParameter name='env.TEST' value='test']"

If it doesn't work try using Powershell runner type as I'm using that for setting it and it works.




回答4:


To expand on the above answers, with powershell it would look like so in build step 1:

Write-Host "##teamcity[setParameter name='env.TEST' value='$test']"

...and you can use the value like this in step 2:

echo %env.Test%

Also as a note, you'll have to set env.Test in the TC build parameters to be equal to something. I just used a space since I know the value will be set via ps script. Hope this helps.




回答5:


It has to be printed to STDOUT, I use cat with heredoc to avoid having to escape single quotes in the event of using variables to dynamically set config parameters. What is heredoc?

MYVARNAME=MYVALUE
cat <<EOF
##teamcity[setParameter name='myConfParameter' value='$MYVARNAME']
EOF

Result:

##teamcity[setParameter name='myConfParameter' value='MYVALUE']

Documentation




回答6:


Here is official ticket about addition double quotes and echo (Write-Host - OS dependency).



来源:https://stackoverflow.com/questions/20829161/teamcity-using-setparameter-to-pass-information-between-build-steps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!