0

I've been trying to pass a build id (and date) to my c++ project via msbuild such that each build that gets created from Jenkins ends up with a build number and date that can be accessed from a panel in my program.

On the surface this seemed like an easy task. Just create a constant definition that gets re-defined by msbuild to be the current date and build number.

I'm trying to pass the build number and ID to msbuild with these command line properties

/p:Configuration=%DebugAxis%;DefineConstants="BUILD_NUMBER=%BUILD_NUMBER%;BUILD_ID=%BUILD_ID%"

And then I just sent my variables that get displayed in my panel to the defined variables:

mBuildNumber = BUILD_NUMBER;
mBuildId = BUILD_ID;

From all the documentation I've read it seems like this should be working but so far no go (the value never changes). Is there a trick to this that I am missing? Note: this is for a C++ NOT C# project.

Joel
  • 352
  • 1
  • 3
  • 11

1 Answers1

0

I am sorry but I am not very clear on the situation you described.

But the Jenkins environment variables are accessed with % sign.

So I would use:

mBuildNumber = %BUILD_NUMBER%

mBuildId = %BUILD_ID%

Also I feel for command line it should be (Not sure on DebugAxis. So no comments there):

/p:Configuration=%DebugAxis%;DefineConstants="BUILD_NUMBER=${BUILD_NUMBER};BUILD_ID=${BUILD_ID}"
NotAgain
  • 1,927
  • 3
  • 26
  • 42
  • My Bad. Did you try : BUILD_NUMBER=${BUILD_NUMBER} etc on the msbuild. In my setup where my NAnt script invokes the msbuild, I use this format to access the Jenkins environment variables. – NotAgain Feb 25 '14 at 00:27
  • We are passing other environment variables in with %%'s and it seems to be working (like %DebugAxis%). Only in this case is the environment variable not making it to C++ as a preprocessor definition. – Joel Feb 25 '14 at 00:36
  • A /t:Rebuild maybe? http://stackoverflow.com/questions/10714668/how-do-you-pass-conditional-compilation-symbols-defineconstants-to-msbuild – NotAgain Feb 25 '14 at 00:50
  • Nope, tried that too. The value still doesn't make it in as a preprocessor definition. Rebuild will be necessary to reset the value though once this is working. Doing this is on the file that uses the preproccesor definition is probably faster though: http://stackoverflow.com/a/923927/158818 – Joel Feb 25 '14 at 01:10
  • You said value never changes. What is the value you are getting. That might give some hints. – NotAgain Feb 25 '14 at 02:52