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

email-ext cannot expand ${FAVORITE_USERS_EMAIL} macro in pipeline

    Details

    • Similar Issues:

      Description

      When passing the ${FAVORITE_USERS_EMAIL} macro in the 'to:' line of a pipeline call to email-ext, jenkins errors with: "FAVORITE_USERS_EMAIL" is not supported in this context. 

      I also cannot expand the ${FAVORITE_USERS_EMAIL} token using the 'tk' step to get the list of users who have favorited a job and include them in the email. The same error message is thrown. 

        Attachments

          Activity

          bbyjnks m c created issue -
          davidvanlaatum David van Laatum made changes -
          Field Original Value New Value
          Labels email-ext favorite pipeline favorite pipeline
          davidvanlaatum David van Laatum made changes -
          Component/s email-ext-plugin [ 15538 ]
          Assignee David van Laatum [ davidvanlaatum ] James Dumay [ jamesdumay ]
          davidvanlaatum David van Laatum made changes -
          Component/s email-ext-plugin [ 15538 ]
          davidvanlaatum David van Laatum made changes -
          Labels favorite pipeline email-ext favorite pipeline
          Hide
          davidvanlaatum David van Laatum added a comment -

          Personally I would code as RecipientProvider rather than a token.

          Show
          davidvanlaatum David van Laatum added a comment - Personally I would code as RecipientProvider rather than a token.
          Hide
          jamesdumay James Dumay added a comment -

          Can you please provide an example Jenkinsfile?

          Show
          jamesdumay James Dumay added a comment - Can you please provide an example Jenkinsfile?
          Hide
          raorao rao rao added a comment -

          I too hit the same issue this morning. Any update or workaround with this issue?

          Show
          raorao rao rao added a comment - I too hit the same issue this morning. Any update or workaround with this issue?
          Hide
          kmleinen Kyle Leinen added a comment -

          Anyone have an example that James can look at?  If not, I'll try and come up with one as I would like to get this resolved.

          Show
          kmleinen Kyle Leinen added a comment - Anyone have an example that James can look at?  If not, I'll try and come up with one as I would like to get this resolved.
          Hide
          kmleinen Kyle Leinen added a comment - - edited

          We tried this was various escape char combos for the "$", but we found that the environment variable on our system isn't showing up even for a simple echo call.

          pipeline {
              agent none
          
              stages {
                  stage('Test Email') {
                      agent any
                      steps {
                          script {
                              try {
                                 echo "emailext body: 'Hello World', recipientProviders: [recipients()], subject: 'Hi', to: '\$FAVORITE_USERS_EMAIL'"
                                 emailext body: 'Hello World - fifth', recipientProviders: [recipients()], subject: 'Hi', to: '\$FAVORITE_USERS_EMAIL'
                              } catch(e) {
                                 echo "${e.getMessage()}"
                                 echo "Failed to send email"
                              }
                          }
                      }
                  }
              }
          }
          
          Show
          kmleinen Kyle Leinen added a comment - - edited We tried this was various escape char combos for the "$", but we found that the environment variable on our system isn't showing up even for a simple echo call. pipeline { agent none stages { stage( 'Test Email' ) { agent any steps { script { try { echo "emailext body: 'Hello World' , recipientProviders: [recipients()], subject: 'Hi' , to: '\$FAVORITE_USERS_EMAIL' " emailext body: 'Hello World - fifth' , recipientProviders: [recipients()], subject: 'Hi' , to: '\$FAVORITE_USERS_EMAIL' } catch (e) { echo "${e.getMessage()}" echo "Failed to send email" } } } } } }
          Hide
          slide_o_mix Alex Earl added a comment -

          is FAVORITE_USERS_EMAIL a token, or just a parameter?

          Show
          slide_o_mix Alex Earl added a comment - is FAVORITE_USERS_EMAIL a token, or just a parameter?
          slide_o_mix Alex Earl made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Incomplete [ 4 ]
          slide_o_mix Alex Earl made changes -
          Assignee James Dumay [ jamesdumay ] Alex Earl [ slide_o_mix ]
          Hide
          raorao rao rao added a comment -

          The workaround that i did is below.

           

          def email_list = []
          if(fileExists ('favorites.txt')) {
           def file_contents = readFile 'favorites.txt'
          email_list = file_contents.tokenize('\n')
           echo "FILE CONTENTS OF FAVORITES ARE -- ${email_list}"
           } else {
           echo "FAVORITES FILE DOESNT EXIST"
           }
          emailext body: "${email_job_url}${currentBuild.description}", recipientProviders: [[$class: 'RequesterRecipientProvider']], mimeType: 'text/html', subject: "Pipeline '${env.JOB_NAME}' was ${currentBuild.result}", to: "${email_list.join(',')}"
          

           

           

          Show
          raorao rao rao added a comment - The workaround that i did is below.   def email_list = [] if (fileExists ( 'favorites.txt' )) { def file_contents = readFile 'favorites.txt' email_list = file_contents.tokenize( '\n' ) echo "FILE CONTENTS OF FAVORITES ARE -- ${email_list}" } else { echo "FAVORITES FILE DOESNT EXIST" } emailext body: "${email_job_url}${currentBuild.description}" , recipientProviders: [[$class: 'RequesterRecipientProvider' ]], mimeType: 'text/html' , subject: "Pipeline '${env.JOB_NAME}' was ${currentBuild.result}" , to: "${email_list.join( ',' )}"    
          Hide
          kmleinen Kyle Leinen added a comment -

          How did that text file get generated?

          Show
          kmleinen Kyle Leinen added a comment - How did that text file get generated?
          Hide
          raorao rao rao added a comment -

          The Favorites plugin generates that file for each job that has been Favorited.

          Show
          raorao rao rao added a comment - The Favorites plugin generates that file for each job that has been Favorited.
          Hide
          slide_o_mix Alex Earl added a comment -

          Where is FAVORITE_USERS_EMAIL defined? Is it a job parameter, or an environment variable? I don't think it is a token (from token-macro). If it's a parameter or environment variable, you should be able to access it as:

          emailext body: 'Hello World - fifth', recipientProviders: [recipients()], subject: 'Hi', to: FAVORITE_USERS_EMAIL
          

          or

          Show
          slide_o_mix Alex Earl added a comment - Where is FAVORITE_USERS_EMAIL defined? Is it a job parameter, or an environment variable? I don't think it is a token (from token-macro). If it's a parameter or environment variable, you should be able to access it as: emailext body: 'Hello World - fifth' , recipientProviders: [recipients()], subject: 'Hi' , to: FAVORITE_USERS_EMAIL or
          Hide
          raorao rao rao added a comment -

          FAVORITE_USERS_EMAIL is a Token Macro as part of [Favorite |https://plugins.jenkins.io/favorite] plugin.

          Show
          raorao rao rao added a comment - FAVORITE_USERS_EMAIL is a Token Macro as part of [Favorite | https://plugins.jenkins.io/favorite ] plugin.
          Hide
          slide_o_mix Alex Earl added a comment -

          That token won't work in a pipeline job, it has not been updated to support pipeline.

          Show
          slide_o_mix Alex Earl added a comment - That token won't work in a pipeline job, it has not been updated to support pipeline.
          slide_o_mix Alex Earl made changes -
          Component/s email-ext-plugin [ 15538 ]
          slide_o_mix Alex Earl made changes -
          Assignee Alex Earl [ slide_o_mix ] James Dumay [ jamesdumay ]
          Show
          slide_o_mix Alex Earl added a comment - See https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/java/hudson/plugins/emailext/plugins/content/FailedTestsContent.java#L46-L96 for an example of how to allow the token to work in pipeline jobs.

            People

            • Assignee:
              jamesdumay James Dumay
              Reporter:
              bbyjnks m c
            • Votes:
              3 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: