Instantly share code, notes, and snippets.

What would you like to do?
Escape character & quotes in Jenkins Pipeline
docker.image('cloudbees/java-build-tools:0.0.6').inside {
sshagent(['github-ssh-credentials']) {
sh """
git version
git config --local \\"\\"
git config --local \\"Cyrille Le Clerc\\"
git clone
date &> now.txt
git commit --all -m \\"another commit\\"
git push origin/master
Started by user admin
[Pipeline] Allocate node : Start
Running on in /home/ubuntu/jenkins-aws-home/workspace/tests/test-git
[Pipeline] node {
[Pipeline] sh
[test-git] Running shell script
+ docker inspect -f . cloudbees/java-build-tools:0.0.6
[Pipeline] Run build steps inside a Docker container : Start
$ docker run -t -d -u 1000:1000 -w /home/ubuntu/jenkins-aws-home/workspace/tests/test-git -v /home/ubuntu/jenkins-aws-home/workspace/tests/test-git:/home/ubuntu/jenkins-aws-home/workspace/tests/test-git:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** cloudbees/java-build-tools:0.0.6 cat
[Pipeline] withDockerContainer {
[Pipeline] SSH Agent : Start
[ssh-agent] Using credentials cyrille-leclerc (GitHub cyrille-leclerc ssh)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Java/JNR ssh-agent
[ssh-agent] Started.
[Pipeline] sshagent {
[Pipeline] sh
[test-git] Running shell script
+ git version
git version 2.1.4
+ git config --local ""
+ git config --local "Cyrille Le Clerc"
usage: git config [options]
Config file location
--global use global config file
--system use system config file
--local use repository config file
-f, --file <file> use given config file
--blob <blob-id> read config from given blob object
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value [value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-e, --edit open an editor
--get-color <slot> find the color configured: [default]
--get-colorbool <slot>
find the color setting: [stdout-is-tty]
--bool value is "true" or "false"
--int value is decimal number
--bool-or-int value is --bool or --int
--path value is a path (file or directory name)
-z, --null terminate values with NUL byte
--includes respect include directives on lookup
[Pipeline] } //sshagent
[Pipeline] SSH Agent : End
[Pipeline] } //withDockerContainer
$ docker stop 6a8ba100abb54669d24cfc7d4b6cae0dfaad727b8f3c7a3ad186690d9ee12d4a
$ docker rm -f 6a8ba100abb54669d24cfc7d4b6cae0dfaad727b8f3c7a3ad186690d9ee12d4a
[Pipeline] Run build steps inside a Docker container : End
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
ERROR: script returned exit code 129
Finished: FAILURE

This comment has been minimized.

imavroukakis commented Sep 29, 2016

i.e. git config --local \\"Cyrille\\ Le\\ Clerc\\"


This comment has been minimized.

bcatubig commented Jan 4, 2017

Just ran into this issue myself.

If it's not clear how to do this, try with 3 single quotes and using double backslashed double quotes


sh '''
    echo Hello \\"World\\"
    echo This is a dollar sign: \\$

This comment has been minimized.

chee commented Jan 10, 2017

surely three single quotes is just the same as one single quote. you're just joining the empty string to either end of it


This comment has been minimized.

vikas027 commented May 1, 2017

Life saver 💯 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment