Search code examples
cjenkinsenvironment-variablespreprocessoriar

IAR print environment variable string : Preprocessor Defined symbols


As part of our Jenkins build, Jenkins has many environment variables. Two of them are BUILD_NUMBER and BRANCH_NAME. We add these to the Preprocessor Defined symbols:

enter image description here

Those environment variables are now accessible at compile time:

#define APPLICATION_VERSION_MAJOR         (1)
#define APPLICATION_VERSION_MINOR         (1)
#define APPLICATION_VERSION_BUILD         (BUILD_NUMBER)
#define GIT_BRANCH_NAME                   (BRANCH_NAME)

using the BUILD_NUMBER is fine, it is a number, but I get an error when trying to use the BRANCH_NAME. For example:

debug(DEBUG_LEVEL_INFO, "software version %d.%d.%d  branch %s", APPLICATION_VERSION_MAJOR, APPLICATION_VERSION_MINOR, APPLICATION_VERSION_BUILD, GIT_BRANCH_NAME);

I get the error:

Error[Pe020]: identifier "localbuild" is undefined D:\repo\source\state_machine.c 284 

The environment variable BRANCH_NAME is set to "localbuild", the compiler is getting the correct value. But, how do can I use it in my code? It works for numbers, but how do I do the same for strings?


Solution

  • Simple answer, a string environment variable must be added like this: BRANCH_NAME="$_BRANCH_NAME_$"