Below is my jenkins pipeline to send a email
The problem is i have some params.variables in my body which i need to use in order for them to be replaced i need to use """
I also have a HTML file which i attach in the body, for which i need to use ' '
Is there any way to combine both of them in the body? Below code gives UNEXPECTED TOKEN FILE, if i replace " with ' , then the params variable is not replaced
emailext (
mimeType: "text/html",
to: 'srav',
subject: "Job '${env.JOB_BASE_NAME}' (${env.BUILD_NUMBER}) is waiting for approval",
body: """<p>Hi</p><p>Defect ${params.DE_NUMBER} is waiting for approval</p><p>${FILE,path="/atm/com/def/de_1886.html"}</p><p>Please go to console output of "${env.BUILD_URL}input" to <font color="green"> Approve</font> or <font color="red">Reject</font> </p><p>Thank You</p><p>DEVOPS TEAM</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'RequesterRecipientProvider']]
)
Related
I have an html email template the represents my pipeline result.
I'm sending the render template by:
emailext body: '${SCRIPT, template="feedback.template"}',
subject: "Full pipeline details",
mimeType: 'text/html',
to: "${config.to}"
I try to send the rendered html report also via slack by:
slackUploadFile filePath: "<MY-rendered-html>", initialComment: "Full Report"
I can't figure out how to get the rendered email-template html for other purpose like sending the html via slack or uploading it to somewhere else
You can use saveOutput: true option
I'm getting this Warning: A secret was passed to "httpRequest" using Groovy String interpolation, which is insecure using the first example here. I made this keyvar = credentials('key_id') as an environmental variable and put it in something like this
def response = httpRequest url: "https://url...",
customHeaders: [[name: 'Authorization', value: "${keyvar}"]]...
Which works but is not how it should be properly done as described in this documentation, so following that I tried what it suggested here, using single quotes and no bracket.
def response = httpRequest url: "https://url...",
customHeaders: [[name: 'Authorization', value: '$keyvar']]...
This solves the first error but now I get Response Code: HTTP/1.1 401 Unauthorized which to me, means that interpolation isn't working within the single quotes as the documentation describes.
To make the answer from Matt Schuchard in the comments more clear for future people stumbling upon this - you need to remove the string interpolation and pass the variable directly:
def response = httpRequest url: "https://url...",
customHeaders: [[name: 'Authorization', value: keyvar]]...
This also works for headers that require an additional prefix (e.g. Bearer):
def response = httpRequest url: "https://url...",
customHeaders: [[name: 'Authorization', value: 'Bearer ' + keyvar]]...
is safe, while
def response = httpRequest url: "https://url...",
customHeaders: [[name: 'Authorization', value: "Bearer $keyvar"]]...
is not.
Instead of httpRequest method, I have the aliOssUpload method. It doesn’t work by passing the argument directly to the argument without recasting as a string.
The interpolation warning can be resolved by escaping the $\keyvar
EmailExt- Jenkinsfile - HTML and CSS files are not embedded
I am trying to attach html report in the email body and send the mail using Email-ext plugin.
email-ext attachmentsPattern: "filePathToBeAttached", mimeType:'text/html', body: readFile("${env.WORKSPACE}/path_to_report.html"),to: acbd#gmail.com", subject:"test report"
But I could see plain HTML without proper formatting and absence of CSS styling in the email report sent.
Any help pls.
This is currently working for me. HTML is properly formatted in the mail, in outlook. I'm not using any css.
unsuccessful {
emailext mimeType: 'text/html',
subject: "${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!",
body: readFile("${env.WORKSPACE}/JenkinsMailBody.html"),
from: 'noreply-jenkins#sofico.be',
replyTo: 'noreply-jenkins#sofico.be',
recipientProviders: [culprits(), requestor()]
}
I am giving the below option in Jenkins,
Post-build Actions:
Content Type: HTML (text/html)
Default Subject: $DEFAULT_SUBJECT
Default Content: ${FILE,path="c:/aaa/bbb/ccc/report.html”}
But if I check the email received via jenkins, its showing the file path in the email body as '${FILE,path="c:/aaa/bbb/ccc/report.html”}' instead of actually displaying the content inside the HTML file
I am using python to trigger a Jenkins job. Right now I'm using python requests lib; I trigger the job directly as:
response = requests.post("https://jenkinsurl/job/myJob/buildWithParameters", auth=(user, password), verify=False)
I need to send build parameters to the job. All tutorials I see, indicate to send the paramaters as a query string on the job URL (example - if I wanted to send params 'param1' with 'val1' and 'param2' with 'val2', I'd post as follows:)
response = requests.post("https://jenkinsurl/job/myJob/buildWithParameters?param1=val1¶m2=val2", auth=(user, password), verify=False)
The problem is that I need to send sensitive params, which I can't supply in plaintext as part of an URL. Is there a way to send the params as part of the post body? I can't seem to find the syntax/structure the json would need be in, to accomplish this.
I was able to get this to work by passing the params directly to the 'data' option in requests.
So in the example above (to send params 'param1' with value 'val1' and 'param2' with value 'val2' to the Jenkins job, this worked:)
var jobParams = {'param1': 'val1', 'param2': 'val2'}
response = requests.post("https://jenkinsurl/job/myJob/buildWithParameters, data=jobParams, auth=(user, password), verify=False)
EDIT: If you are facing this issue, make sure not to solve it by sending the params to requests' 'params' arg - it will work (trigger the job with the params) but all it's doing is generating the query string for you - those param/values would still get tacked on the URL