My pipeline fails at the sh """ element of the Jenkinsfile. Any idea where things go wrong?
stage('Install dependencies') { when { expression { return params.dependencies } } } steps { sh """ apt-get update apt-get install -y openssh-server net-tools inetutils-ping python-pip rubygems apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ gnupg2 \ software-properties-common curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable" apt-get update apt-get install -y docker-ce docker-ce-cli containerd.io curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose gem install serverspec pygmy """ } }
The error message is:
WorkflowScript: 35: illegal string body character after dollar sign; solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 35, column 17.
Replace double quotes """
with single quotes '''
.
sh ''' apt-get update //... '''
Whenever Groovy sees $
inside the double quotes, it treats this string as GString
and does string interpolation. However, in your case, a character $
is not used in the context of interpolation and it fails. Alternatively, you could escape \$
but it makes more sense to switch to single quoted string.
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