TeamCity - using setParameter to pass information between build steps

前端 未结 6 1804
清歌不尽
清歌不尽 2020-12-23 22:04

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 o

相关标签:
6条回答
  • 2020-12-23 22:14

    you need to echo that string, e.g.

    echo "##teamcity[setParameter name='env.TEST' value='test']"
    
    0 讨论(0)
  • 2020-12-23 22:25

    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.

    0 讨论(0)
  • 2020-12-23 22:34

    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.

    0 讨论(0)
  • 2020-12-23 22:35

    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

    0 讨论(0)
  • 2020-12-23 22:35

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

    0 讨论(0)
  • 2020-12-23 22:36

    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.

    0 讨论(0)
提交回复
热议问题