I'm trying to send out an email when my Jenkins build ends. The HTML file gets generated in a previous step and I have verified its location.
This is the error that's being generated [Error replacing 'FILE' - Error processing tokens]
always {
emailext (mimeType: 'text/html',
body: '${FILE, path="report_stage.html"}',
subject: currentBuild.currentResult + " : " + env.JOB_NAME,
to: "${params['On Failure Email List']}"
)
}
Related
I want to add the Generated Html report in the mail when using Jenkins pipeline post actions.
Path of the HTML reports in the workspace : /var/lib/jenkins/workspace/State_Check_Listings_Live_Apartmentlove/22/execution/node/3/ws/automation-report/reports/07-11-2022/
But I'm not getting any attachments in the mail please help
Using declarative pipeline script
Used script in post actions
emailext mimeType: 'text/html',
attachmentsPattern: "</var/lib/jenkins/workspace/State_Check_Listings_Live_Apartmentlove/28/execution/node/3/ws/automation-report/reports/07-11-2022/>",
body:'Check console output at $BUILD_URL to view the results. \n\n ${CHANGES} \n\n -------------------------------------------------- \n${BUILD_LOG, maxLines=100, escapeHtml=false}',
to: "${EMAIL_TO}",
subject: 'Stage Second Fails in Jenkins: $PROJECT_NAME - #$BUILD_NUMBER'
I'm working with Junit/Ant .I wrote this script in Default contents, but it sends me a report with passed and failed tests, and I'd want it to be the only with a failed tests.
Jenkins Report!
Configuration :
Project Name : $PROJECT_NAME
Project URL : $PROJECT_URL
Build number: #$BUILD_NUMBER
Job Description: $JOB_DESCRIPTION
Execution Results :
Status : $BUILD_STATUS
Run: ${TEST_COUNTS}, Failed: ${TEST_COUNTS,var="fail"}, Passed: ${TEST_COUNTS,var="pass"}, Skipped: ${TEST_COUNTS,var="skip"}
Report preview :
hi you can create email template and configure the email-ext step like below:
emailext body: '''${SCRIPT, template="groovy-html.template"}''',
subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Successful",
mimeType: 'text/html',to: "to list"
here the groovy-html.template is the default template which jenkins pickup and render the result in that template. You can edit this email template to have only failed tests and save that template in the $JENKINS_HOME/email-templates directory and use this template.
Note : use different name for the template other than groovy-html.template.
I have below script in Jenkins
if diff file1.txt file2.txt > file3.txt ; then
echo "no difference"
else
<need to send email notitication>
fi
I heard like we can achieve this using 'Email-ext plugin', I have plugin installed in my Jenkins.
Could any one can explain that how to use Email-ext plugin to send mail based on script condition.
hi you can refer to this link for detailed steps to configure email template. In your pipeline script you can add below step to get notification:
emailext body: ''
'${SCRIPT, template="groovy-html.template"}'
'', subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Successful",
mimeType: 'text/html', to: "email list"
The groovy-html.template is default template which you can use or write your own content in email body and subject.
I have downloaded & installed Slack Notification Plugin in jenkins and using slackSend in the pipeline, it was working before but now getting an error as below: After this i downloaded Global Slack Notifier plugin, but still the same error,is there any setup required? Please advice
[Pipeline] slackSend
run slackstepsend, step null:false, desc null:false
Slack Send Pipeline step configured values from global config - baseUrl: true, teamDomain: true, token: true, channel: false, color: false
ERROR: Slack notification failed. See Jenkins logs for details.
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE
Code is as below:
if (dstry) {
def status = sh(returnStatus: true, script: "set +e; terraform plan -destroy -var-file=my.tfvars -out=destroy.tfplan")
echo "Plan Status : ${status}"
def destroyExitCode = sh(returnStatus: true, script: "set +e; terraform destroy -auto-approve")
echo "Terraform Destroy Exit Code: ${destroyExitCode}"
if (destroyExitCode == "0") {
slackSend channel: '#ci', color: 'good', message: "Destroy Applied ${env.JOB_NAME} - ${env.BUILD_NUMBER} ()"
currentBuild.result = 'SUCCESSFUL'
} else {
slackSend channel: '#ci', color: 'danger', message: "Destroy Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER} ()"
currentBuild.result = 'FAILURE'
}
}
Did you add the slack Jenkins token for integration?
Go to this Jenkins CI url, search for your team domain, then add a new configuration. Copy the name of the token or the token itself. Then go to your Jenkins pipeline script and add to slackSend, the domain and the token credential ID or the token in plain text (not secured). Should look something like this:
slackSend channel: '#ci', color: 'good', message: "Destroy Applied ${env.JOB_NAME} - ${env.BUILD_NUMBER}", teamDomain: 'your_domain.slack.com', tokenCredentialId: 'your_id'
or if you want to use the token in plain text token:'your_token' instead of the tokenCredentialId
Hope this helps!
I like to commit my Jenkins email script to my working copy and use it with Email-ext.
So I wrote something like :
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
always {
echo 'Sending email...'
emailext body: '''${SCRIPT, template="${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template"}''',
mimeType: 'text/html',
subject: "[Leeroy Jenkins] ${currentBuild.fullDisplayName}",
to: "user#company.com",
replyTo: "user#company.com",
recipientProviders: [[$class: 'CulpritsRecipientProvider']]
}
}
}
But I get the following mail:
Groovy Template file [${WORKSPACE}SrcScriptsJenkinsgroovy-html2.template] was not found in $JENKINS_HOME/email-templates.
Templates must live in the correct directory for security reasons. If you want to keep them in a SCM I suggest you create a Jenkins job that checks out that SCM to the correct directory. Technically though that directory shouldn't be writable but probably is. Alternatively you can use the groovy code in the pipeline itself
On Jenkins 2.190, using a local workspace file as a jelly template, works well. It is pulled with SCM step during the build, and the correct html content is received.
This is the Default Content of my email-ext configuration:
${JELLY_SCRIPT,template="${WORKSPACE}/some_dir/email_template.jelly"}
Solve it by manually overriding the file using command line:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
always {
echo 'Sending email...'
bat "copy /Y ${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template \"${JENKINS_HOME}\\email-templates\\groovy-html2.template\""
emailext body: '''${SCRIPT, template="${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template"}''',
mimeType: 'text/html',
subject: "[Leeroy Jenkins] ${currentBuild.fullDisplayName}",
to: "user#company.com",
replyTo: "user#company.com",
recipientProviders: [[$class: 'CulpritsRecipientProvider']]
}
}
}
A bit crude, but it works.