Environment variables & build scripts

I need to store data from a build script. I was hoping to store it in a environment variable, which i have created in project.
I have tried:
export  %env.mydata%="some-data"
I need to store this var as it's used in the build dependencies of the following project.

Neither of these seem to work. I can't find anywhere how I can do this.


1 comment
Comment actions Permalink

Are you trying to pass data to a builld script, retrieve some build result from a build script or what?

If you need to pass data from TeamCity to a build script, then a build parameter of the form "env.mydata" will appear as an environment variable called "mydata" in your build script.

You cannot ever set or return any values directly to TeamCity via environment variables, it just doesn't work that way.

If you want to affect teamcity behavior via your build script, you would need to use one or more of the following techniques:

  • TeamCity service messages
  • TeamCity rest API

If you wish to persist the result of a build script and possibly use that result in another build script, you need to create a build artifact and pass it on via an artifact dependency.

So, for example, you could have one build script write a file like so:

echo "mydata=abcde" >my_environment.sh

Then you ensure you declare the my_environment.sh as a build artifact in the build config that runs that script.

Then you pull in my_environment.sh into a different build via an artifact dependency

Finally, in the downstream buildscript, you have the line:

. ./my_environment.sh # <- yes, with the "." which means textually include ...

Then your new buildscript will get the value of "mydata" from the upstream one.


Please sign in to leave a comment.