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

EMail-Ext does not send email, because or empty recipients

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Critical
    • Resolution: Unresolved
    • Component/s: git-plugin, scm-api-plugin
    • Labels:
      None
    • Environment:
      master node on Ubuntu x64
      slave node on Windows
    • Similar Issues:

      Description

      I send my mail via groovy script in a multibranch-pipeline (blue ocean)

      script 
                  {
                      def currResult = getResultAsString(currentBuild)
                      def prevResult = getResultAsString(currentBuild.getPreviousBuild())
                      if (currResult != "SUCCESS" || prevResult != "SUCCESS") 
                      {
                           echo 'send mail'
                           emailext body: '''${SCRIPT, template="my-html.template"}''',
                                  recipientProviders: [[$class: 'DevelopersRecipientProvider'],
                                                       [$class: 'CulpritsRecipientProvider'],
                                                       [$class: 'UpstreamComitterRecipientProvider'],
                                                      ],
                                  subject: '[Jenkins]: ${JOB_NAME} ${BUILD_DISPLAY_NAME} - ' + currResult,
                                  mimeType: 'text/html'
                      }
                      
                  }
      
      def getResultAsString(build)
      {
          def result = build?.result
          if (result == null) {
              result = "SUCCESS"
          }
          return result;
      }
      

      When creating a new branch and adding a commit which will fail this build,
      jenkins will not send a email, with following message:

      An attempt to send an e-mail to empty list of recipients, ignored.
      

      However, when adding another commit to the same branch, jenkins, will now surprisingly have a commiter email address and can send the email.
      So always the first build of a new branch, email-ext will not retrieve a correct email from the commit.

      Can you please fix it?

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment -

          Zack Snyder sorry, but I don't use the email-ext plugin. I would assume that the block in your example which says

                                      recipientProviders: [[$class: 'DevelopersRecipientProvider'],
                                                           [$class: 'CulpritsRecipientProvider'],
                                                           [$class: 'UpstreamComitterRecipientProvider']
                                                          ] ${author_email},
          

          should instead say:

                                      recipientProviders: [[$class: 'DevelopersRecipientProvider'],
                                                           [$class: 'CulpritsRecipientProvider'],
                                                           [$class: 'UpstreamComitterRecipientProvider']
                                                          ] author_email,
          

          In this case, author_email is a variable.

          Show
          markewaite Mark Waite added a comment - Zack Snyder sorry, but I don't use the email-ext plugin. I would assume that the block in your example which says recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider'], [$class: 'UpstreamComitterRecipientProvider'] ] ${author_email}, should instead say: recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider'], [$class: 'UpstreamComitterRecipientProvider'] ] author_email, In this case, author_email is a variable.
          Hide
          zack Zack Snyder added a comment -

          Mark Waite
          It still does not work. The other error is:

          WorkflowScript: 75: expecting '}', found ',' @ line 75, column 100.
             DISPLAY_NAME} - ' + currResult,
          

          The retrieve of the email address does not work perfectly, I get in fact the whole command back:

          def author_email = bat(returnStdout:true,  script:'git log -n 1 --pretty=format:%%ae')
                          echo "author E-mail is ${author_email}"
          

          Leads to following output:

          author E-mail is 
          G:\jenkins\workspace\app_test-email-branch-27DKLR7UW4OLTKKVCAORJQDJDVIHVIRGU2SWE3JRP7LEG3QEVBWQ>git log -n 1 --pretty=format:%ae 
          user@mail.de
          

          What do you think?

          Show
          zack Zack Snyder added a comment - Mark Waite It still does not work. The other error is: WorkflowScript: 75: expecting '}', found ',' @ line 75, column 100. DISPLAY_NAME} - ' + currResult, The retrieve of the email address does not work perfectly, I get in fact the whole command back: def author_email = bat(returnStdout:true, script:'git log -n 1 --pretty=format:%%ae') echo "author E-mail is ${author_email}" Leads to following output: author E-mail is G:\jenkins\workspace\app_test-email-branch-27DKLR7UW4OLTKKVCAORJQDJDVIHVIRGU2SWE3JRP7LEG3QEVBWQ>git log -n 1 --pretty=format:%ae user@mail.de What do you think?
          Hide
          markewaite Mark Waite added a comment -

          In the case of the unexpected extra output in the stdout of the bat step, that is apparently JENKINS-44569. I confirmed with my test job that the technique described in JENKINS-44569 works. I disagree with the resolution of JENKINS-44569 as "Not a defect", but that's a different topic.

          I'm no help on the Pipeline scripting syntax error. I've used the "Pipeline Syntax" link on the page to assist with generating the correct syntax for Pipeline steps.

          Show
          markewaite Mark Waite added a comment - In the case of the unexpected extra output in the stdout of the bat step, that is apparently JENKINS-44569 . I confirmed with my test job that the technique described in JENKINS-44569 works. I disagree with the resolution of JENKINS-44569 as "Not a defect", but that's a different topic. I'm no help on the Pipeline scripting syntax error. I've used the "Pipeline Syntax" link on the page to assist with generating the correct syntax for Pipeline steps.
          Hide
          davidvanlaatum David van Laatum added a comment -

          you need to add a to parameter, recipientProviders is a list of classes that generate recipients

          emailext body: '', subject: '', to: 'abc@example.com'

          Show
          davidvanlaatum David van Laatum added a comment - you need to add a to parameter, recipientProviders is a list of classes that generate recipients emailext body: '', subject: '', to: 'abc@example.com'
          Hide
          zack Zack Snyder added a comment -

          David van Laatum
          This works. Thanks.
          The thing is, I always cleanup my build dir when the develop branch is build.

          when { branch 'develop' }
                       steps {
                          echo 'Clean up workspace...'
                          deleteDir()
                      }
          

          This will lead to the behaviour that the complete git dir is removed and git does not work anymore.
          So my post script will try to perfom a git log and I get this:

          fatal: Not a git repository (or any of the parent directories): .git
          
          G:\jenkins\workspace\app_develop-NBDLPDI4IZVRV4I2HQPT77BU7XOUGHLE5BQFTJBAVDWCAQXXBCVQ>git log -n 1 --pretty=format:%ae 
          
          script returned exit code 128
          

          Any Idea how I can fix this?

          I need something like this:

          If (branch('develop') {
          author_email = bat(script: 'git log -n 1 --pretty=format:%%ae', returnStdout:true).trim().split("\n")
           }
          

          Do you know how I can check in the post step for the current branch name?

          Show
          zack Zack Snyder added a comment - David van Laatum This works. Thanks. The thing is, I always cleanup my build dir when the develop branch is build. when { branch 'develop' } steps { echo 'Clean up workspace...' deleteDir() } This will lead to the behaviour that the complete git dir is removed and git does not work anymore. So my post script will try to perfom a git log and I get this: fatal: Not a git repository (or any of the parent directories): .git G:\jenkins\workspace\app_develop-NBDLPDI4IZVRV4I2HQPT77BU7XOUGHLE5BQFTJBAVDWCAQXXBCVQ>git log -n 1 --pretty=format:%ae script returned exit code 128 Any Idea how I can fix this? I need something like this: If (branch('develop') { author_email = bat(script: 'git log -n 1 --pretty=format:%%ae', returnStdout:true).trim().split("\n") } Do you know how I can check in the post step for the current branch name?

            People

            • Assignee:
              Unassigned
              Reporter:
              zack Zack Snyder
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: