Configuring email-ext plugin

875 views
Skip to first unread message

John Roberdeau

unread,
Apr 23, 2015, 3:13:31 PM4/23/15
to job-dsl...@googlegroups.com
I am trying to use the email-ext plugin to send an email on build success. I am new to Job DSL. My approach was to setup what I wanted with the UI and then reverse-engineer the Job DSL from the config.xml for the modified job. I now have identical XML, but it is not showing up on the configure screen, and it doesn't work. Help would be appreciated.

We want to be able to selectively turn this on per build, so the call to this method goes in an if statement when we are putting together our configure steps.

def addExtendedEmailPlugin(jobObj) {
   jobObj.configure { project ->
      project / publishers << 'hudson.plugins.emailext.ExtendedEmailPublisher'(plugin:"email-ext"){
         'recipientList'('som...@email.com')
 
         'configuredTriggers' {
            'hudson.plugins.emailext.plugins.trigger.SuccessTrigger' {
               'email' {
                  recipientList('som...@email.com')
                  subject('aSubject')
 body('aBody')
 'recipientProviders' {
    'hudson.plugins.emailext.plugins.recipients.ListRecipientProvider'()
 }
 attachmentsPattern()
                  attachBuildLog(false)
                  compressBuildLog(false)
                  replyTo('$PROJECT_DEFAULT_REPLYTO')
                  contentType('project')
               }
            }
         }
contentType('default')
defaultSubject('myDefaultSubject')
defaultContent('myDefaultContent')
         attachmentsPattern()
         presendScript()
         attachBuildLog(false)
         compressBuildLog(false)
         replyTo('$DEFAULT_REPLYTO')
         saveOutput(false)
         disabled(false)  
      }
   }
}


Here's the XML for this block:

<hudson.plugins.emailext.ExtendedEmailPublisher plugin="email-ext">
<recipientList>som...@email.com</recipientList>
<configuredTriggers>
<hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
<email>
<recipientList>som...@email.com</recipientList>
<subject>aSubject</subject>
<body>aBody</body>
<recipientProviders>
<hudson.plugins.emailext.plugins.recipients.ListRecipientProvider/>
</recipientProviders>
<attachmentsPattern/>
<attachBuildLog>false</attachBuildLog>
<compressBuildLog>false</compressBuildLog>
<replyTo>$PROJECT_DEFAULT_REPLYTO</replyTo>
<contentType>project</contentType>
</email>
</hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
</configuredTriggers>
<contentType>default</contentType>
<defaultSubject>myDefaultSubject</defaultSubject>
<defaultContent>myDefaultContent</defaultContent>
<attachmentsPattern/>
<presendScript/>
<attachBuildLog>false</attachBuildLog>
<compressBuildLog>false</compressBuildLog>
<replyTo>$DEFAULT_REPLYTO</replyTo>
<saveOutput>false</saveOutput>
<disabled>false</disabled>
</hudson.plugins.emailext.ExtendedEmailPublisher>

This XML is identical to what I get when I configure this in the UI, but when I use the Job DSL plugin, it isn't working. This stuff doesn't populate the configure page, and if I run the build, this gets excised from the XML (which I presume happens to extraneous/invalid material). I have spent far too long fighting with what seems like it should have been a two hour task. Thanks for your help.

RM

unread,
Apr 23, 2015, 7:48:24 PM4/23/15
to job-dsl...@googlegroups.com
Is there a reason you are using the configure block? The Job DSL Plugin has much better support for the Email Ext Publisher.

I use the email ext publisher which works with much lesser code (from https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-reference)

Now there may be scenarios where you may end up using the configure block but it will be for minor tweaks.

Can you check the XML again, i haven't compared it but very often there is a plugin version against the plugin element which seems to be missing in your case.

As a thumb rule, prefer the DSL over the configure block when you can. Good Luck.

job {
    publishers {
        extendedEmail(String recipients = null, String subjectTemplate = null,
                      String contentTemplate = null) {
            trigger(String triggerName, String subject = null, String body = null,
                    String recipientList = null, Boolean sendToDevelopers = null,
                    Boolean sendToRequester = null, includeCulprits = null,
                    Boolean sendToRecipientList = null)
            trigger(Map args)
            configure(Closure configureClosure)
        }
    }
}

John Roberdeau

unread,
Apr 24, 2015, 11:20:33 AM4/24/15
to job-dsl...@googlegroups.com
I had tried it both with and without the plugin version, and it made no difference.

I rewrote it using the standard DSL syntax:

def addExtendedEmailPlugin(jobObj, vars) {
   jobObj.publishers {
      extendedEmail("som...@email.com", "defaultSubject", "defaultContent") {
         trigger(triggerName: "Success", subject: "SuccessSubject", body: "SuccessBody", recipientList: "som...@email.com",
    sendToDevelopers: false, sendToRequester: false, includeCulprits: false, sendToRecipientList: true)
   }
   }
}

That generates this XML:

<hudson.plugins.emailext.ExtendedEmailPublisher>
<recipientList>som...@email.com</recipientList>
<contentType>default</contentType>
<defaultSubject>defaultSubject</defaultSubject>
<defaultContent>defaultContent</defaultContent>
<attachmentsPattern/>
<configuredTriggers>
<hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
<email>
<recipientList>som...@email.com</recipientList>
<subject>SuccessSubject</subject>
<body>SuccessBody</body>
<sendToDevelopers>false</sendToDevelopers>
<sendToRequester>false</sendToRequester>
<includeCulprits>false</includeCulprits>
<sendToRecipientList>true</sendToRecipientList>
</email>
</hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
</configuredTriggers>
</hudson.plugins.emailext.ExtendedEmailPublisher>

Which seems like it should be fine. It is not as close to what I get using the UI (for example, that includes a <recipientProvider> pair, but I have no idea what that is, of course), but it also doesn't work. I generate the job, check the XML, and find the above, but when I look at the configuration screen or run the job, it's not there.

Daniel Spilker

unread,
Apr 24, 2015, 11:48:58 AM4/24/15
to job-dsl...@googlegroups.com
If you installed the Email-ext plugin after the Job DSL plugin, you need to restart Jenkins before you use the DSL to configure a job with the new plugin.

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/f1b617f4-ac86-4d64-a671-f2373f7071eb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

John Roberdeau

unread,
Apr 27, 2015, 11:39:51 AM4/27/15
to job-dsl...@googlegroups.com
Yep, that was the problem. Thanks for the help, but that is just about the most frustrating root cause I can imagine. I should not have made the assumption that because the plugin works without a restart, this would. Not a mistake I'll be making again.

Daniel Spilker

unread,
Apr 27, 2015, 2:13:00 PM4/27/15
to job-dsl...@googlegroups.com
Sorry about the inconvenience. Please open an issue in JIRA: https://issues.jenkins-ci.org/browse/JENKINS/component/16720.

Reply all
Reply to author
Forward
0 new messages