3

I have a python script that runs as build step in teamcity 9.0. Now I need to know the branch name from which the build is triggered. I could use %teamcity.build.branch% to get the branch name. But I need it to be passed on to my script so that I can use it for some condition checking. Is this possible? How? Please help me out.

  • Are you using the Python Build Runner (https://code.google.com/p/teamcity-python/) or a Command Line Build Runner? Is the script inline or in a source code file? – Matt Jun 03 '15 at 07:11
  • @DevOps Its only a script written in `python3.4` and is run from terminal as `python3.4 MyScript.py`.This script is kept in the build server. – S M ANANTHARAMAN Jun 03 '15 at 07:21

1 Answers1

3

You can pass parameters to a python script if you're running it from a terminal, so the code you need to run will be

$ python MyScript.py %teamcity.build.branch%

Alternatively, install the python build runner as this will help you to pass parameters through to scripts / source code through the UI

Runner

Python Build Runner

Hope this helps

Matt
  • 3,684
  • 1
  • 17
  • 19
  • 1
    So how can we use this `%teamcity.build.branch%` inside the script. I tried a sample of the above and tried to store `%teamcity.build.branch%` to a variable as `variable = %teamcity.build.branch%`. This gives me acompilation error when run from teamcity. – Nevin Raj Victor Jun 03 '15 at 09:38
  • Can you show the compilation error? If this is a python issue then I'd suggest reading through something like this - https://docs.python.org/3.4/library/argparse.html – Matt Jun 03 '15 at 10:10
  • @EvolveSoftwareLtd Using this solution in a powershell script made all of my agents incompatible with "Implicit Requirement" errors. – dckuehn Mar 22 '17 at 15:04
  • It could be that you need a root branch specification. http://stackoverflow.com/questions/22314229/why-did-my-teamcity-build-stop-working Effectively the variable isn't available at the point of running the build for some reason. – Matt Mar 23 '17 at 09:08