2

I'm making a declarative Jenkins pipeline which has a for loop to iterate over the output of a bash command. In that command it is necessary to use bash arguments e.g. "$1" for first argument. And it is a series of pipes with many types of quotes.

I tried using the triple double quotes for a raw string in groovy but it seems groovy is still trying to parse "$1" as me trying to reference the value of a variable named "1". So, this is not expected "raw string" behavior.

How does one go about doing this?

Here's an example of what the command is like.

kubectl get namespaces --no-headers -o=custom-columns=":.metadata.name,:.metadata.creationTimestamp" | grep -E "myproject_" | awk '$2 <= "'$(date -d'now-2 days' -Ins --utc | sed 's/+0000/Z/')'"{print $1}' | sed 's/myproject_//g'"""

Ignore the specifics of the command. My question is purely how does one get around the dollar sign syntax errors. The actual command is something different.

1 Answer 1

1

Either use a single-quoted string, or escape the dollar sign with a backslash:

echo('This is a literal dollar sign: $')
echo("This is a literal dollar sign: \$")

Both will print This is a literal dollar sign: $ to the Jenkins console output.

By the way, this question was already asked and answered over on StackOverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.