Issue
I have a jenkins job, and part of the code looks like this:
def version = sh returnStdout: true, script: """ #!/bin/sh
find src/*/*/ -name *.ear | grep -Eo \'[0-9]+\\.[0-9]+\\.[0-9]+\'
"""
sh "echo $version"
def imageVersion = sh returnStdout: true, script: """
#!/bin/sh
curl -k -H 'X-JFrog-Art-Api:${api_key}' https://artifactory.xxx.com/api/search/latestVersion\\?g=com.xxx.bwce&a=billing-app-v1&v=$version-SNAPSHOT&repos=libs-snapshot-local
"""
And I noticed that during the execution, this curl statement is broken at this variable replacement.
here is how the output looks from Jenkins console log.
+ echo 1.0.6
1.0.6
[Pipeline] sh
+ curl -k -H X-JFrog-Art-Api:**** 'https://artifactory.xxx.com/api/search/latestVersion?g=com.xxx.bwce&a=billing-app-v1&v=1.0.6'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 23 0 23 0 0 34 0 --:--:-- --:--:-- --:--:-- 34
+ '-SNAPSHOT&repos=libs-snapshot-local'
Please suggest if there is a way to fix this. I am not sure why its adding a newline in the curl statement, but echo shows no newline in it.
Solution
You can trim the newline off the end of version
by adding the line
version = version.trim()
After your def version =
line
Answered By - tim_yates