I have a file 'README.txt' which contains the line -
"version": "1.0.0-alpha-test.7"
Using a Jenkins Pipeline, I want to replace this line with
"version": "1.0.0-alpha-test.{BUILD_NUMBER}"
The following sed command works when I try it on a linux cluster
sed -i -E "s#(\"version\"[ ]*:[ ]*\".+alpha-test\.)[0-9]+\"#\1${BUILD_NUMBER}#g" README.txt
The same command does not work using a Jenkins Pipeline.
Tried with the following query but it doesn't work -
sh """
sed -i -E "s|([\"]version[\"][ ]*:[ ]*[\"].+alpha-test\\.)[0-9]+\"|\1${BUILD_NUMBER}|g" README.txt
cat README.txt
"""
/home/jenkins/workspace/test/test-pipeline@tmp/durable-eb774fcf/script.sh: 3: /home/jenkins/workspace/test/test-pipeline@tmp/durable-eb774fcf/script.sh: Syntax error: ")" unexpected
{BUILD_NUMBER}
in the output but your code is trying to insert${BUILD_NUMBER}
- what should really appear in the output - the text{BUILD_NUMER}
or the value of the shell variable${BUILD_NUMBER}
or something else? – Ed Morton"
to'
for the sed command:sed -i -E 's|([\"]version[\"][ ]*:[ ]*[\"].+alpha-test\\.)[0-9]+\"|\1${BUILD_NUMBER}|g' README.txt cat README.txt
– Onur Gokkocabas