Skip to content

[JENKINS-55474] \n in code with is merged doesn't reflect in Jenkins UI and post build notification doesn't work  #178

@jenkins-infra-bot

Description

@jenkins-infra-bot

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}",​

 

 


Originally reported by biswas_jenkin100, imported from: \n in code with is merged doesn't reflect in Jenkins UI and post build notification doesn't work
  • status: In Progress
  • priority: Major
  • component(s): groovy-postbuild-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20251216-225446
Raw content of original issue

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}",​

 

 

  • environment: Jenkins version 2.107.3
2 attachments

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions