I'm running into a weird issues with a pipeline script. I have a multi line sh blob like
sh """
git tag -fa \\"${version}\\" -m \\"Release of ${version}\\"
"""
And this somehow runs as:
+ git tag -fa '"1.0-16-959069f'
error: Terminal is dumb, but EDITOR unset
Please supply the message using either -m or -F option.
So its dropping the -m
and message. I've tried single escapes, double escapes, nothing seems to work.
The safest way to handle this is usually to single quote the argument: In a Jenkins pipeline, this whole thing has to be put into a String, meaning it has to be wrapped in quotes itself. At first glance, we can just wrap it in double quotes so single quotes don’t need to be escaped, and we get string interpolation for the input:
Escaping quotes is a special nightmare in shell scripts generally, but Jenkins adds yet another layer of confusion on top of that. I’m going to cut through that layer and find out what Jenkins is actually executing. Today I was trying to format a shell command that included a user argument that could contain special characters.
Then there is Jenkin's sh command (plus the shell process the command will start), then ssh, then the remote shell which ssh will start, then the bash which you start. One of them is removing the \ before $4 which breaks your AWK script.
Today I was trying to format a shell command that included a user argument that could contain special characters. The safest way to handle this is usually to single quote the argument: In a Jenkins pipeline, this whole thing has to be put into a String, meaning it has to be wrapped in quotes itself.
I have no idea why this worked but this did
def tagGithub(String version) {
def exec = """
git tag -d ${version} || true
git push origin :refs/tags/${version}
# tag new version
git tag -fa ${version} -m "Release of ${version}"
git push origin --tags
"""
sh exec
}
Something with the inline jenkins groovy interpolation seems busted, doing the interpolation in another var and then executing it worked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With