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

Pipeline withEnv changes not observable in email-ext groovy template

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Minor Minor
    • email-ext-plugin
    • None
    • Jenkins ver. 2.32.3, email-ext plugin 2.57.1

      Given the following Jenkins pipeline code:

      String customEmailContent = "<h5>Custom HTML content</h5>"

      withEnv(["CUSTOM_EMAIL_CONTENT=$\{customEmailContent}"]) {
          steps.emailext(to: "person@company.com",
                         subject: "Subject",
                         mimeType: "text/html",
                         body: '${SCRIPT, template="my-groovy-html.template"}',
                         recipientProviders: null)
      }

      I would expect to be able to see the "CUSTOM_EMAIL_CONTENT" environment variable available inside the template. However, that does not appear to be the case. I've tried a number of different approaches mentioned in various message boards (ex: using build.environment["CUSTOM_EMAIL_CONTENT"] in the template, using env.CUSTOM_EMAIL_CONTENT=customEmailContent in the pipeline code), but the environment variable is never there.

      Am I missing something?

          [JENKINS-43403] Pipeline withEnv changes not observable in email-ext groovy template

          Alex Earl added a comment -

          Did you try using ENV(var: 'CUSTOM_EMAIL_CONTENT') in the template?

          Alex Earl added a comment - Did you try using ENV(var: 'CUSTOM_EMAIL_CONTENT') in the template?

            slide_o_mix Alex Earl
            ccoleman Curt Coleman
            Votes:
            9 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: