[JIRA] (JENKINS-51218) EMail-Ext does not send email, because or empty recipients

3 views
Skip to first unread message

zack81@gmx.net (JIRA)

unread,
May 9, 2018, 8:13:02 AM5/9/18
to jenkinsc...@googlegroups.com
Zack Snyder created an issue
 
Jenkins / Bug JENKINS-51218
EMail-Ext does not send email, because or empty recipients
Issue Type: Bug Bug
Assignee: David van Laatum
Attachments: installed_plugins.txt
Components: email-ext-plugin
Created: 2018-05-09 12:12
Environment: master node on Ubuntu x64
slave node on Windows
Priority: Critical Critical
Reporter: Zack Snyder

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?

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

david@vanlaatum.id.au (JIRA)

unread,
May 9, 2018, 10:57:02 AM5/9/18
to jenkinsc...@googlegroups.com
David van Laatum closed an issue as Won't Fix
 

This is not actually a fault with emailext its with the SCM api. First build has no build to compare it to so no way to determine what has happened since. emailext purely asks the SCM api for this info

Change By: David van Laatum
Status: Open Closed
Resolution: Won't Fix

zack81@gmx.net (JIRA)

unread,
May 9, 2018, 12:01:02 PM5/9/18
to jenkinsc...@googlegroups.com
Zack Snyder commented on Bug JENKINS-51218
 
Re: EMail-Ext does not send email, because or empty recipients

But it has the info who has committed the changes.
So how can it be fixed? How can I get the developer of the current commit which is been building?

david@vanlaatum.id.au (JIRA)

unread,
May 10, 2018, 2:03:02 AM5/10/18
to jenkinsc...@googlegroups.com

Determining who is the developer of a build is done by jenkins and the SCM api not emailext. If you look at the build details and you see no changelog emailext has no hope

zack81@gmx.net (JIRA)

unread,
May 14, 2018, 4:02:02 AM5/14/18
to jenkinsc...@googlegroups.com


You are right, the git change log looks like its missing the important details...strange.

zack81@gmx.net (JIRA)

unread,
May 14, 2018, 4:02:02 AM5/14/18
to jenkinsc...@googlegroups.com
Zack Snyder updated an issue
 
Change By: Zack Snyder
Component/s: git-plugin
Component/s: scm-api-plugin

zack81@gmx.net (JIRA)

unread,
May 14, 2018, 4:02:02 AM5/14/18
to jenkinsc...@googlegroups.com
Zack Snyder updated an issue
Change By: Zack Snyder
Attachment: jenkins_changes.jpg

zack81@gmx.net (JIRA)

unread,
May 14, 2018, 4:03:02 AM5/14/18
to jenkinsc...@googlegroups.com
Zack Snyder edited a comment on Bug JENKINS-51218
 
Re: EMail-Ext does not send email, because or empty recipients
!jenkins_changes.jpg|thumbnail!
You are right, the git change log looks like its missing the important details...strange.

[~davidvanlaatum]
Can you please reopen and change the assignee?

david@vanlaatum.id.au (JIRA)

unread,
May 14, 2018, 4:17:03 AM5/14/18
to jenkinsc...@googlegroups.com
David van Laatum reopened an issue
 
Change By: David van Laatum
Resolution: Won't Fix
Status: Closed Reopened
Assignee: David van Laatum Mark Waite

david@vanlaatum.id.au (JIRA)

unread,
May 14, 2018, 4:17:03 AM5/14/18
to jenkinsc...@googlegroups.com

mark.earl.waite@gmail.com (JIRA)

unread,
May 14, 2018, 8:33:02 AM5/14/18
to jenkinsc...@googlegroups.com
Mark Waite assigned an issue to Unassigned
Change By: Mark Waite
Assignee: Mark Waite

mark.earl.waite@gmail.com (JIRA)

unread,
May 14, 2018, 8:38:01 AM5/14/18
to jenkinsc...@googlegroups.com
Mark Waite commented on Bug JENKINS-51218
 
Re: EMail-Ext does not send email, because or empty recipients

The changelog of the first build of a branch is always empty. That is how it has always been.

The changelog reports changes since the preceding build. There is no preceding build on the first build and no changelog for the first build.

zack81@gmx.net (JIRA)

unread,
May 14, 2018, 10:06:02 AM5/14/18
to jenkinsc...@googlegroups.com

Mark Waite
Okay, but how can I get what I want?
When I make a new branch, push this new branch to origin a new build is triggered (code was changed, a commit is associated with my email address)
How can the user gets notified that the build was successful?

mark.earl.waite@gmail.com (JIRA)

unread,
May 15, 2018, 12:36:23 PM5/15/18
to jenkinsc...@googlegroups.com

Zack Snyder I think there are several different ways to get the information you want.

You could save the return value of the checkout step and use the GIT_* entries in that map (though see JENKINS-45489 for a bug which may affect that technique for your case). That is described in a Jenkins Minute video and in the documentation

You could call git log -n 1 and read the output of git log for the author name.

david@vanlaatum.id.au (JIRA)

unread,
May 15, 2018, 10:36:03 PM5/15/18
to jenkinsc...@googlegroups.com

I can see the point that when a new multi-branch job is created by the creation of a new branch it does make sense that the commit(s) that created the branch should really be counted as a change. Not sure how feasible this is though.

mark.earl.waite@gmail.com (JIRA)

unread,
May 15, 2018, 10:54:02 PM5/15/18
to jenkinsc...@googlegroups.com

I can think of many different ways to define the set of changes which should be displayed in job creation. Some examples that immediately come to mind include:

  • No changes, this is the first job on the branch so there can't be any changes (current behavior)
  • Tip of the new branch (as requested by Zack Snyder)
  • Chain of changes on the branch compared to a defined base branch (use double dot comparison notation)
  • Chain of changes on the branch since it diverged from a defined base branch (use triple dot comparison notation as described on stackoverflow) - matches a common technique of creating a new branch and adding several commits to the branch before I push it to the remote git server
  • Fixed number of changes on the branch (branch created which was created as an orphan)

I'm sure there are other scenarios as well. Unfortunately, I don't intend to change the current behavior. I believe @Zack can get the behavior he wants from within Pipeline, and others could do the same, without requiring changes to the git plugin (and the 130000 installations of the git plugin).

mark.earl.waite@gmail.com (JIRA)

unread,
May 15, 2018, 11:01:02 PM5/15/18
to jenkinsc...@googlegroups.com
Mark Waite edited a comment on Bug JENKINS-51218
I can think of many different ways to define the set of changes which should be displayed in job creation.  Some examples that immediately come to mind include:

* No changes, this is the first job on the branch so there can't be any changes (current behavior)
* Tip of the new branch (as requested by [~zack])
* Chain of changes on the branch compared to a defined base branch (use double dot comparison notation)
* Chain of changes on the branch since it diverged from a defined base branch (use triple dot comparison notation as described on [stackoverflow|https://stackoverflow.com/questions/9725531/show-commits-since-branch-creation]) - matches a common technique of creating a new branch and adding several commits to the branch before I push it to the remote git server
* Fixed number of changes on the branch (branch created which was created as an [orphan|https://stackoverflow.com/questions/5689960/how-do-i-create-a-commit-without-a-parent-in-git])

I'm sure there are other scenarios as well.  Unfortunately, I don't intend to change the current behavior.  I believe
@Zack [~zack] can get the behavior he wants from within Pipeline, and others could do the same, without requiring changes to the git plugin (and the 130000 installations of the git plugin).

david@vanlaatum.id.au (JIRA)

unread,
May 15, 2018, 11:09:02 PM5/15/18
to jenkinsc...@googlegroups.com

I just think it logically makes sense when a new branch is created in a multi branch style job that the creation of the branch should be classified as a change which in turn would cause every other plugin that uses the list of developers/commiters to do something would pick this up. I think most users would expect this to be the case in multi branch. Not sure if the responsibility to do this lives in the multi branch plugin, scm api, the scm plugin/driver or a combination, I just think its what users would expect, I know I would, not that I have actually tested with SVN (which I use I work).  I could code a special case in emailext but I think it would be better if its handled globally

zack81@gmx.net (JIRA)

unread,
May 16, 2018, 2:50:02 AM5/16/18
to jenkinsc...@googlegroups.com

Mark Waite
Okay, you can say I can get the email address of the user how changed the code with git log -n 1
I am new to jenkins and do not understand how to do it properly.

Can you please show me the complete code, see the pipeline script above how I send the email, can you adjust it?

zack81@gmx.net (JIRA)

unread,
May 16, 2018, 2:51:39 AM5/16/18
to jenkinsc...@googlegroups.com
Zack Snyder edited a comment on Bug JENKINS-51218
[~markewaite]
Okay, you
can say I can get the email address of the user how changed the code with {{git log -n 1}}

I am new to jenkins and do not understand how to do it properly.

Can you please show me the complete code, see the pipeline script above how I send the email, can you adjust it?

zack81@gmx.net (JIRA)

unread,
May 16, 2018, 2:52:03 AM5/16/18
to jenkinsc...@googlegroups.com

zack81@gmx.net (JIRA)

unread,
May 16, 2018, 7:07:03 AM5/16/18
to jenkinsc...@googlegroups.com
Zack Snyder edited a comment on Bug JENKINS-51218
[~markewaite]
Okay, you say I can get the email address of the user
how who changed the code with {{git log -n 1}}

I am new to jenkins and do not understand how to do it properly.

Can you please show me the complete code, see the pipeline script above how I send the email, can you adjust it?


PS: IMHO, I think the git scm plugin should return this info, creating a branch, with no changes is one thing, but creating a branch with changes, it is clear for me that this are changes.

mark.earl.waite@gmail.com (JIRA)

unread,
May 16, 2018, 7:42:02 AM5/16/18
to jenkinsc...@googlegroups.com

Zack Snyder I think you can get the e-mail address of the author of the most recent commit with the Pipeline command:

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

The git log documentation provides more details if you need to extract other information from that commit and the sh step documentation can provide additional pointers for its use.

If you're on Windows, replace sh with bat

zack81@gmx.net (JIRA)

unread,
May 17, 2018, 12:42:02 PM5/17/18
to jenkinsc...@googlegroups.com

Mark Waite
Okay, with some minor changes I can retrive the mail address.
However, how can I use it with ext-mail?

def author_email = bat(returnStdout:true,  script:'git log -n 1 --pretty=format:%%ae')
                echo "author E-mail is ${author_email}"
                
                def currResult = getResultAsString(currentBuild)
                def prevResult = getResultAsString(currentBuild.getPreviousBuild())
                if (currResult != "SUCCESS" || prevResult != "SUCCESS") 
                {
                     echo 'send mail'
                     emailext body: '''${SCRIPT, template="xion-html.template"}''',
                            recipientProviders: [[$class: 'DevelopersRecipientProvider'],
                                                 [$class: 'CulpritsRecipientProvider'],
                                                 [$class: 'UpstreamComitterRecipientProvider']
                                                ] ${author_email},
                            subject: '[Jenkins]: ${JOB_NAME} ${BUILD_DISPLAY_NAME} - ' + currResult,
                            mimeType: 'text/html'
                }

I got following error:

WorkflowScript: 74: expecting '}', found ',' @ line 74, column 66.

                ] ${author_email},

mark.earl.waite@gmail.com (JIRA)

unread,
May 17, 2018, 12:52:02 PM5/17/18
to jenkinsc...@googlegroups.com

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.

zack81@gmx.net (JIRA)

unread,
May 18, 2018, 3:42:02 AM5/18/18
to jenkinsc...@googlegroups.com

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 
us...@mail.de

What do you think?

mark.earl.waite@gmail.com (JIRA)

unread,
May 18, 2018, 9:43:03 AM5/18/18
to jenkinsc...@googlegroups.com

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.

david@vanlaatum.id.au (JIRA)

unread,
May 18, 2018, 8:36:02 PM5/18/18
to jenkinsc...@googlegroups.com

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

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

zack81@gmx.net (JIRA)

unread,
Jun 14, 2018, 12:03:01 PM6/14/18
to jenkinsc...@googlegroups.com

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?

mark.earl.waite@gmail.com (JIRA)

unread,
May 19, 2019, 10:56:02 PM5/19/19
to jenkinsc...@googlegroups.com
Change By: Mark Waite
Status: Reopened Open
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

6081986@gmail.com (JIRA)

unread,
Apr 28, 2020, 8:50:02 AM4/28/20
to jenkinsc...@googlegroups.com
This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages