Issue
I'm doing a simple substitution, and this works fine at the command line:
sed "s/pub Url =.*/pub Url = 'https:\/\/example.com:3207';/g" myfile.ts
I'm trying to run it within a Jenkinsfile, and like 40 builds later I cannot get the escape quoting right.
Pretty sure it will look something like this:
sh 'sed \\"s/pub Url =.*/pub Url = \\'https:\\\/\\\/example.com:3207\\';/g\\" myfile.ts'
Yet that results in the following error:
WorkflowScript: 4: unexpected char: '\' @ line 4, column 49.
ub Url =.*/pub Url = \\'https:\\\/\\\/ex
I feel like I've tried dozens of variants but nothing is working.
Here is among the most common errors I'm getting: which points to escaping issue
sed: -e expression #1, char 1: unknown command: `"'
I really just need a pipeline expert that can likely see exactly what I'm doing wrong and know where to quote it.
As noted here: https://gist.github.com/Faheetah/e11bd0315c34ed32e681616e41279ef4 this is not uncommon to fight this type of stuff in the pipeline files and it seems like it's just trial and error.
Solution
Ok after much trial and error, this is working.
Looks like I had to use triple single quotes around the command. Good thing I don't need to interpolate!
sh '''sed \"s/pub Url =.*/pub Url = \\'https:\\/\\/example.com:3207\\';/g\" afile.txt'''
Hope this is helpful to someone in the future that's fighting this!
Answered By - emmdee Answer Checked By - Marilyn (WPSolving Volunteer)