Oh my… what’s going on here?

We’re feeding contents of the TeamCity build properties file into a loop, with grep -v '^#' filtering out lines that begin with # (comments). Each line is parsed by read which configured to split the line by = (IFS) into key and value. Then we’re using printf -v to declare environment variables for non empty keys with trimmed values.

Please note that dots are replaced by underscores because no one can use dots in Bash variables. For example, system property agent.name becomes accessible by $agent_name.

And how can I use it?

I suggest you to avoid using weird parameter names (like this guy ლ(ಠ益ಠლ)) and stay simple with default syntax. As far as you can see this is not a complete parser of JAVA properties and it’s robustness is in question, but it works reasonably well with TeamCity-generated files. This script is not perfect and I welcome every positive feedback for it. See also corresponding gist.

Conclusion

Now you can safely decouple your Bash scripts from TeamCity almighty textarea and place them into proper git repo.