0

I'm trying to delay the expansion of variables within Jenkins Parameters until the parameter used. For example:

I have a job parameter "EMAIL_SUBJECT" which might contain a reference to a variable that will change throughout the build. EG: "My build of $GIT_HASH". Where the value of "GIT_HASH" might change throughout the build.

In old versions of EnvInject every time EMAIL_SUBJECT was used it would reference the newest value of GIT_HASH. Like this:

  1. Start build with parameter EMAIL_SUBJECT="My build of $GIT_HASH"
  2. Do some work and set GIT_HASH=A
  3. EMAIL_SUBJECT is "My build of A"
  4. Do some work and set GIT_HASH=B
  5. EMAIL_SUBJECT is "My build of B"

However in newer versions of EnvInject (1.77+) EMAIL_SUBJECT is evaluated once and never updates. So the above becomes:

  1. Start build with parameter EMAIL_SUBJECT="My build of $GIT_HASH"
  2. Do some work and set GIT_HASH=A
  3. EMAIL_SUBJECT is "My build of A"
  4. Do some work and set GIT_HASH=B
  5. EMAIL_SUBJECT is "My build of A"

I've tried escaping the variable with backslashes in the parameter but EnvInject doesn't like that either and escapes my escapes, so the result ends up being the same string just with a "\" proceeding the value. EMAIL_SUBJECT=My build of \$GIT_HASH Ends up outputting: My build of \A

My question: Is there a way to stop EnvInject from overriding a parameter? Or any environment variable for that matter?

  • You can add a build step of updating the environment `Inject environment variables` – KeepCalmAndCarryOn Mar 18 '14 at 22:20
  • I'm not sure how that applies? I know how to inject environment variables in my project, but I don't see how that helps me keep variables from expanding in parameters. Perhaps I'm missing something? – Em0ry42 Mar 20 '14 at 23:41
  • I was thinking you could rebuild the environment variable in an intermediate step between steps but I guess you don't hard code it but set it based on some condition. This may be what you're looking for where you build a props file and load it in http://stackoverflow.com/questions/10625259/how-to-set-environment-variables-in-jenkins – KeepCalmAndCarryOn Mar 21 '14 at 00:17

0 Answers0