Reputation: 7
I'm trying to have Jenkins pipeline automatically send an email, but with a custom body. The pipeline is called from a web application by a button, so I was thinking about having a text box there to write the desired message before the button is pressed. However, I don't know how this chunk of text can get sent to Jenkins.
Right now the pipeline is sending emails through emailext, with the body message hardcoded. I know I can pass data from a web app to Jenkins with the Build With Parameters API, which I'm currently using for a Username and Password field, but sending a whole email message as a parameter sounds incorrect.
emailext (
subject: "---subject---",
body: """Hi,
This is the hardcoded message that I would the user to have flexibility to create themselves
""",
to: "---list of recipients---"
)
Upvotes: 0
Views: 1488
Reputation: 269
Ist thing you job needs a parameter MAILTEST and then you can just this parameter in the body of the email just like coldplayer proposed.
Honestley for I used https://wiki.jenkins.io/display/JENKINS/Generic+Webhook+Trigger+Plugin because the default trigger support only a kind of token as parameter on the rest interface.
Upvotes: 0
Reputation: 289
You can also use something like this, where you could add REGEX and EXCERPT to customize your mail content
emailext(
to: "email_list",
subject: "Subject",
body: '''$BUILD_URL
${BUILD_LOG_REGEX, regex="DRYRUN.*DRYRUN.*DRYRUN",maxMatches=1, showTruncatedLines=false}
${BUILD_LOG_EXCERPT, start="EMAIL CONTENT:",end="END OF EMAIL CONTENT"}''',
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
Upvotes: 2
Reputation: 41
Here is a function ready to be executed, you can also add an attachment. Adapt to your needs.
def sendMail() {
def body = """
<html>
<body>
<p>Hello</p>
<p><img src="cid:screenshot.jpg" alt="screenshot"/></p>
<ul>
<li><strong>Jenkins Build URL:</strong> ${env.BUILD_URL}</li>
</ul>
</body>
</html>
"""
emailext(to: recipient, subject: 'SUCCESS : ' + subject, body: body, mimeType: 'text/html', attachmentsPattern: 'screenshot.jpg')
}
Upvotes: 0