Setting an environment variable in a build step?

I'd like to set an environment variable dynamically based on the hostname of the agent running the configuration
target_host=`hostname -s`
##teamcity[setParameter name='env.target_host' value='$target_host']


When I try to display the value in another build step to verify that it worked, the value is blank in both instances

echo "=== target_host is $target_host ==="
echo "=== target_host is %env.target_host% ==="


Also, I have defined in the build parameters an empty env.target_host parameter (in case an existing parameter was needed to be overridden by the build script interaction)

Is what I am trying to do possible? How can I make it work?

1 comment
Comment actions Permalink

Hi Andy

To get this to work I found I had to reference the build in which the environment variable was created (defined)  when accessing it from another project.

I defined an environment variable called RELEASE_BUILD_NUMBER .    To access within  the build it was created in is was %env.RELEASE_BUILD_NUMBER%

To access it from another build I had to fully reference it  i.e   %dep.bt5.env.RELEASE_BUILD_NUMBER%

The bt5  is a the build definition assigned by TeamCity for the build in which the enjoinment variable  was defined

Must admit would be nice if teammcity allowed you to use the build name   instead of the "magic" number  btX" but have not found a way to do that.

0

Please sign in to leave a comment.