jenkinsjenkins-email-ext

Extract the value of an environment variable in Jenkins build configuration


I would like to extract the value of an environment variable and put it in my Editable Email Notification's subject line. I tried with ${ENV,var="MY_ENV_VARIABLE"}, but that simply returns an empty string in the email subject.

Please note, I'm setting MY_ENV_VARIABLE inside my build step (Execute shell) by adding a command export MY_ENV_VARIABLE="some value".

Please help.


Solution

  • This answer helped me. Here's what I did:

    1. Removed the export MY_ENV_VARIABLE=my_value from my build step.
    2. Installed the Environment Injector Plugin in Jenkins and restarted Jenkins.
    3. Added a build step "Inject environment variables" in my build configuration and entered the declaration MY_ENV_VARIABLE=my_value in the "Properties Content" text box.
    4. Finally, added ${ENV, var="MY_ENV_VARIABLE"} in my email's subject in Jenkins.

    The email subject now shows the value of MY_ENV_VARIABLE.