SVN revision variable not working in script

Env: CentOS release 5.4 (Final)
TeamCity version: 5.0.1

One of my builds uses a shell script to execute the build. One step does an export of subversion code. For reasons I have yet to figure out, running a step where a specific revision is checked out is successful when I run the script from a command line but fails to set the revision when I run it through TeamCity.

Pertinent code:
if [ -z ${BUILD_VCS_NUMBER_1} ]; then
        BUILD_VCS_NUMBER_1="`svn status -uq | tail -1 | awk -F':' '{print $2}'`"
fi

svn export --force  http://100.100.100.1/svn/Data -r ${BUILD_VCS_NUMBER_1}

The result is:  svn: missing argument: r

Questions:
1) Does TeamCity set a different variable for SVN at build time when you have a single VCS for a build config?
2) Why would the above work at a command line but not when run through TeamCity?

Thanks,
-Dave

4 comments

How many VCS roots do you use for this build configuration? If there is only one VCS root, you can use BUILD_VCS_NUMBER without _1 suffix.
If there is more than one VCS root, you have to specify: BUILD_VCS_NUMBER_<simplified vcs root name>. It is simpler to take a look at available parameters popup (click on the icon in text field in build configuration settings) and find the exact name there.

0

> How many VCS roots do you use for  this build configuration? If there is only one VCS root, you can use  BUILD_VCS_NUMBER without _1 suffix.

There is only one.

> It is simpler to take a look at available parameters popup  (click on the icon in text field in build configuration settings) and  find the exact name there.

I did look at it. Do I have to set a system or environmental variable to make this work through TeamCity?

e.g. Should this work?

Setup an environmental variable in the build config like this:
Name               Reference Syntax                           Value
SVN_REV       %env.build.vcs.number%           %env.build.vcs.number%

if [ -z ${SVN_REV} ]; then
        SVN_REV="`svn status -uq | tail -1 | awk -F':' '{print $2}'`"
fi

svn  export --force  http://100.100.100.1/svn/Data -r ${SVN_REV}

I'm not clear what is required to make this work. For example we add the build information to our MANIFEST.MF files by simply using the BUILD_NUMBER variables.
Why would my original script not work using this variable: BUILD_VCS_NUMBER_1 when it attempts to use the value of that variable or if it is zero, it sets the value based on the current version used by the build?
As I wrote, this works at a command line but not through TeamCity.

-Dave

0

Have you tried to use BUILD_VCS_NUMBER without _1 suffix? This environment variable should be set by TeamCity, there is no need to perform additional actions.

0

I just got back to trying this again. It appears to work properly now.

I believe the solution to this was a combination of:

  • Changing the variable to BUILD_VCS_NUMBER
  • Changing the build config(s) to use automatic checkout on agent


As a precaution, I have the script set the BUILD_VCS_NUMBER if it is zero length to the value of: svn status -uq | awk '{print $4}'


-Dave

0

Please sign in to leave a comment.