Are setenv hudson plugin variables accessible in status email?
Asked Answered
V

3

1

I installed the SetEnv plugin and it works fine for getting the variables during a task.

unfortunately when i try to use the env variable in the resulting status email I have no luck at all. Is this supposed to work?

I've tried both $VARNAME and ${VARNAME} - neither of which get replaced correctly in the email.

Vortex answered 19/12, 2010 at 17:6 Comment(0)
N
3

The simplest way to use environment variables (or any variables) in your email notifications is by using the Email-ext plugin.

Check their "Content token reference" for specifics but in short you get much more sophisticated substitution. Heres a few I use regularly:

  • ${ENV, var} - Displays an environment variable.
  • ${BUILD_LOG_REGEX, regex, linesBefore, linesAfter, maxMatches, showTruncatedLines} - Displays lines from the build log that match the regular expression.
  • ${CHANGES_SINCE_LAST_SUCCESS, reverse, format, showPaths, changesFormat, pathFormat} - Displays the changes since the last successful build.
  • ${FAILED_TESTS} - Displays failing unit test information, if any tests have failed.

The plugin makes it easy to define a base "global" template in the Hudson configuration then sort of "extend" that template in your job configuration- adding additional detail. It also allows you to route notifications more granularly based on the build status/outcome.

Nubbly answered 21/12, 2010 at 18:36 Comment(4)
I AM using that plugin. The point is that the other plugin that allows me to add env vars does not seem to "export" the value into the email plugin.Vortex
I guess the implementation of the SetEnv-plugin injects the variable into each build step (Hudson uses a new shell for every build step). Since the Email-ext does not create a separate shell, I am not expecting the Email-ext plugin to have the additional environment variables. Might be an interesting feature request for both plug ins. The question is here, what needs to be changed in what plug in, to make it work.Unbeaten
I did find something interesting yesterday - a new plugin definition/requirements being made. A NEW email plugin to replace the core and the email plugin. I added the request to have access to the env vars. (wiki.hudson-ci.org/display/HUDSON/The+new+EMailer)Vortex
The confluence page for this new plugin was created on Aug 05, 2009 02:00. Therefore I would not expect that the plugin will arrive soon. BTW, the page is there for collecting the requirements. I don't know if someone already started to implement something.Unbeaten
C
2

This is possible already. It looks like you're using the wrong syntax. As mentioned previously, the email-ext plugin has a specific method for accessing environment variables. Try putting this in the email body instead:

${ENV, var=VARNAME}

An alternative method would be to use Hudson's execute shell feature to echo the environment variable during the build and parsing for it using BUILD_LOG_REGEX.

For example, you could have this in the Execute Shell part:

echo "Output: ${VARNAME}"

and parse it in the email using

${BUILD_LOG_REGEX, regex="^Output:", showTruncatedLines=false, substText=""}
Chubby answered 22/12, 2010 at 5:8 Comment(0)
V
0

It looks like I will have to wait for this:

http://wiki.hudson-ci.org/display/HUDSON/The+new+EMailer

Vortex answered 21/12, 2010 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.