TeamCity - using setParameter to pass information

2019-02-01 15:53发布

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.

标签: teamcity
6条回答
劳资没心,怎么记你
2楼-- · 2019-02-01 15:58

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.

查看更多
萌系小妹纸
3楼-- · 2019-02-01 16:02

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

查看更多
smile是对你的礼貌
4楼-- · 2019-02-01 16:03

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楼-- · 2019-02-01 16:10

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.

查看更多
叼着烟拽天下
6楼-- · 2019-02-01 16:18

you need to echo that string, e.g.

echo "##teamcity[setParameter name='env.TEST' value='test']"
查看更多
仙女界的扛把子
7楼-- · 2019-02-01 16:19

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

查看更多
登录 后发表回答