Issue
I'm executing a nodejs script in my pipeline and for some reason Jenkins adds a newline after a variable.
The code:
sh """cd /var/jenkins/fcs/cars/ && node validateCommit.js \"${reporthashref}\" 'Suzuki, Ignis'"""
When the pipeline is called it fails. The console output looks like this:
18:08:07 + node validateCommit.js a0ccb50b
18:08:07 Suzuki, Ignis
A new line is added and the command is doing something else.
I remember I had to change this already 1-2 times. Everything worked and now it shows up again.
Is there a proper way to do it?
Solution
Use the trim function to remove spaces and new lines before and after your variable :
${reporthashref.trim()}
Answered By - fmdaboville