i am trying to do git checkout in a jenkins pipeline and trying to find out only the addition of the lines in a pariticular file. however it is throing me error at the dollar sign on the dynamic branch name but the same thing worked elsewhere in the pipeline. the only new addition to the code is the git diff line to find only the addition of the new lines in a particular file. Can you help me to acheive that.
working code:
script{
withCreentials(...){
sh returnStdout: true, script: """
gwit checkout -B ${env.branch}
git config user.name 'xxx'
git config user.email 'xxx@xxx.com'
git add sample.txt
git commit -m "updated from pipeline"
git push origin HEAD:${env.branch}
"""
}
}
not working code:
script{
withCreentials(...){
sh returnStdout: true, script: """
git checkout -B ${env.branch}
git config user.name 'xxx'
git config user.email 'xxx@xxx.com'
git diff HEAD^:sample.txt HEAD:sample.txt --color=always|perl -wine 'print $1 if /^\e\[32m\+\e\[m\e\[32m(.*)\e\[m$/'> output.txt
}
}
error is :
illegal string boy character
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}"
git checkout -B ${env.branch}
^