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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • git-plugin, scm-api-plugin
    • None
    • master node on Ubuntu x64
      slave node on Windows

    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

          zack Zack Snyder added a comment -

          markewaite
          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?

          zack Zack Snyder added a comment - markewaite 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?
          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.

          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.

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

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

          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'
          zack Zack Snyder added a comment -

          davidvanlaatum
          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?

          zack Zack Snyder added a comment - davidvanlaatum 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?
          dm_lapin Dmitrii Lapin added a comment - Same older ticket:  https://issues.jenkins-ci.org/browse/JENKINS-24638

          People

            Unassigned Unassigned
            zack Zack Snyder
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: