-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
Jenkins version 2.107.3
If anyone could help me with the below issue :-
I have added a post build code by selecting the groovy post build Plugin .The code was validated and merged as it was source controlled , but when I go to Jenkins UI ,I get the below error as attached in Snapshot and Jenkins doesn't notify the build information in Microsoft Teams Properly .
startup failed:
Script1.groovy: 16: expecting anything but ''\n''; got it anyway @ line 16, column 47.
text: "${type} Build:
^
1 error
post build code that runs fine in Local jenkins :-
import groovy.json.JsonOutput
import hudson.model.*
def param = manager.build.buildVariables.get("abcEnv")
def currDate = new Date()
def formattedDate = currDate.format("MM/dd/yyy")
def build_number = manager.build.number
def job_name = manager.build.project.getName()
def start_user = User.get(manager.build.causes[0].userId)
def CustomText = manager.build.buildVariables.get("CustomText")
def sendMessage(type, color, configuration, execution, param, formattedDate, build_number, job_name,start_user, CustomText ) {
json_payload = JsonOutput.toJson( [
title: "Job Notification",
summary: "Job Notification",
text: "${type} Build: \n Build id : #${build_number} \n Job Name: ${job_name} ${execution.status} at ${formattedDate} in the environment ${param} Started by the user ${start_user}. ${CustomText}",
themeColor: "${color}",
potentialAction: [
[
"@context": "http://schema.org",
"@type": "ViewAction",
name: "Seed job execution",
target: ["${execution.href}"]
]
]
])
return json_payload
}
configuration = [
'webhook_url': 'can put any webhook here from teams' ]
execution = [
'id': 'someID',
'project': 'project',
'status': 'success',
'dateEnded': 'Today?'
]
type = "START"
color = "228B22"
json_payload = sendMessage(type, color, configuration, execution, param, formattedDate, build_number, job_name,start_user, CustomText)
process = [ 'bash', '-c', "curl -v -k -X POST -H \"Content-Type: application/json\" -d '${json_payload}' ${configuration.webhook_url}" ].execute().text
print process
After Code is Merged in Jenkins UI groovy post build we see this block below:-
\n is not reflected post compilation.
text: "${type} Build:
Build id : #${build_number}
Job Name: ${job_name} ${execution.status} at ${formattedDate} in the environment ${param} Started by the user ${start_user}. ${CustomText}",