Search code examples
buildproperties

Jenkins Groovy postbuild script can't access injected environment variables


I'm trying to get a Groovy script that runs as a post-build step in a Jenkins job to access an injected variable but it keeps getting null.

I've kept the job as simple as possible so there are only 2 real bits of configuration to consider.

Here's how the property is injected. I could use other methods but this is intended for a more complicated job that reads in external properties.

Injecting the variable

This is the Groovy script I have so far. It will do something else with the value once it gets it.

The Groovy post-build script

This is the logging from running the job.

The build logging

I'm not a Groovy expert and I've searched and tried a number of things but without success.


Solution

  • Of course having posted a question I then got the answer myself...

    New script:

    enter image description here

    New logging:

    enter image description here