Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-13277

Global environment variables are not being resolved in Email Notification Recipients list for maven 2/3 projects

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • maven-plugin
    • None

      When using a global environment variable, defined in "Manage Jenkins > Configure System > Environment Variables" (e.g. "ALERT_EMAIL_LIST"), in the "Email Notification > Recipients" list of a maven 2/3 project (e.g. "${ALERT_EMAIL_LIST}") the environment variable is not resolved. In the console output we see: "Sending e-mails to: ${ALERT_EMAIL_LIST}@test.com".

      Note that it DOES work in an "free-style software project".

      So, it does not work within <hudson.maven.reporters.MavenMailer>, but it does work within <hudson.tasks.Mailer>.

          [JENKINS-13277] Global environment variables are not being resolved in Email Notification Recipients list for maven 2/3 projects

          jfreej added a comment -

          Update: Simple build parameters are not working either. When I create a build parameter "ALERT_EMAIL_LIST" and set "Email Notification > Recipients" to "${ALERT_EMAIL_LIST}", I see: "Sending e-mails to: ${ALERT_EMAIL_LIST}@test.com".

          Again, this only applies to <hudson.maven.reporters.MavenMailer>.

          jfreej added a comment - Update: Simple build parameters are not working either. When I create a build parameter "ALERT_EMAIL_LIST" and set "Email Notification > Recipients" to "${ALERT_EMAIL_LIST}", I see: "Sending e-mails to: ${ALERT_EMAIL_LIST}@test.com". Again, this only applies to <hudson.maven.reporters.MavenMailer>.

          Alex Earl added a comment -

          Email Notification is not the email-ext plugin.

          Alex Earl added a comment - Email Notification is not the email-ext plugin.

          Brent Duffy added a comment -

          We are seeing a similar issue with freestyle jobs on Jenkins 2.32.1. The problem we are seeing is that if an environment variable (or build parameter) isn't defined, the variable name is treated as a string literal instead of an empty string. We see this behavior in the "Recipients" field for the built-in "E-mail notification" post-build action as well as the "Project Recipient List" for the "Editable Email Notification" post-build action provided by the email-ext plugin. To replicate this issue, try to refer to an undefined environment variable in one of those fields. The environment variable syntax we're using in the recipient list is:

          emailaddress1 emailaddress2 ${TEST_EMAIL_LIST}

          Basically, emails will always be delivered to emailaddress1 and emailaddress2, but some jobs need to supply additional email addresses via the TEST_EMAIL_LIST build parameter. We have a job that is a downstream to several other jobs. Some of the upstream jobs (but not all) supply TEST_EMAIL_LIST as a build parameter to the downstream job. When the variable is actually defined, everything works as expected, however when it is not defined, both the built-in "Email notification" and the "Editable Email Notification" plugin will try to send an email to the address "$TEST_EMAIL_LIST", which causes an error since it is not a valid address. We would expect that an undefined environment variable would be treated as an empty string, which is how they are treated in the bash shell.

          Brent Duffy added a comment - We are seeing a similar issue with freestyle jobs on Jenkins 2.32.1. The problem we are seeing is that if an environment variable (or build parameter) isn't defined, the variable name is treated as a string literal instead of an empty string. We see this behavior in the "Recipients" field for the built-in "E-mail notification" post-build action as well as the "Project Recipient List" for the "Editable Email Notification" post-build action provided by the email-ext plugin. To replicate this issue, try to refer to an undefined environment variable in one of those fields. The environment variable syntax we're using in the recipient list is: emailaddress1 emailaddress2 ${TEST_EMAIL_LIST} Basically, emails will always be delivered to emailaddress1 and emailaddress2, but some jobs need to supply additional email addresses via the TEST_EMAIL_LIST build parameter. We have a job that is a downstream to several other jobs. Some of the upstream jobs (but not all) supply TEST_EMAIL_LIST as a build parameter to the downstream job. When the variable is actually defined, everything works as expected, however when it is not defined, both the built-in "Email notification" and the "Editable Email Notification" plugin will try to send an email to the address "$TEST_EMAIL_LIST", which causes an error since it is not a valid address. We would expect that an undefined environment variable would be treated as an empty string, which is how they are treated in the bash shell.

          Facing same issue. Do we have any resolution for that?

          Priyank Bamoriya added a comment - Facing same issue. Do we have any resolution for that?

          Code changed in jenkins
          User: André Tadeu de Carvalho
          Path:
          src/main/java/hudson/maven/MavenModuleSetBuild.java
          src/main/java/hudson/maven/reporters/MavenMailer.java
          src/main/java/hudson/maven/util/VariableExpander.java
          src/test/java/hudson/maven/reporters/MavenMailerTest.java
          src/test/java/hudson/maven/util/VariableExpanderTest.java
          http://jenkins-ci.org/commit/maven-plugin/f6112cb4e7fece3c5dd48c93a68f61649bad0b7b
          Log:
          JENKINS-13277 Global Environment Variables in Email notification. (#101)

          • JENKINS-13277 Fix 'Global environment variables are not being resolved in Email Notification Recipients list for maven 2/3 projects'
          • Add integration tests.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: André Tadeu de Carvalho Path: src/main/java/hudson/maven/MavenModuleSetBuild.java src/main/java/hudson/maven/reporters/MavenMailer.java src/main/java/hudson/maven/util/VariableExpander.java src/test/java/hudson/maven/reporters/MavenMailerTest.java src/test/java/hudson/maven/util/VariableExpanderTest.java http://jenkins-ci.org/commit/maven-plugin/f6112cb4e7fece3c5dd48c93a68f61649bad0b7b Log: JENKINS-13277 Global Environment Variables in Email notification. (#101) JENKINS-13277 Fix 'Global environment variables are not being resolved in Email Notification Recipients list for maven 2/3 projects' Add integration tests.

            olamy Olivier Lamy
            jfreej jfreej
            Votes:
            5 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: