I am not sure if its appropriate and if there is a way to continue posting question the existing thread as this:
sed error: "invalid reference \1 on `s' command's RHS" and Invalid reference \1 using sed when trying to print matching expression
The issue I am facing is with the Jenkins (2.249.1) pipeline script:
pipeline {
agent any
stages {
stage("exp") {
steps {
script {
def output=sh(returnStdout: true, script: "echo ab4d | sed 's/b\\(([0-9]\\))/B\\1/' ").trim()
echo "output=$output";
}
}
}
}
}
When run the build, I get this o/p where I was expecting only "B4"
+ echo ab4d
+ sed 's/b\(([0-9]\))/B\1/'
[Pipeline] echo
output=ab4d
The second version that I tried was : def output=sh(returnStdout: true, script: "echo ab4d | sed 's/b\([0-9]\)/B\1/' ").trim()
+ echo ab4d
+ sed 's/b\([0-9]\)/B\1/'
[Pipeline] echo
output=aB4d
With the third version: def output=sh(returnStdout: true, script: "echo ab4d | sed 's/b([0-9])/B\1/' ").trim()
+ echo ab4d
+ sed 's/b([0-9])/B\1/'
sed: -e expression #1, char 15: invalid reference \1 on `s' command's RHS
The output I want is just B4. Please let me know the right approach to fix this issue, and help me understand sed in Pipeline
PS: I am not sure what my Jenkins supports and what it doesn't with respective to using -r option, etc... So I purposely avoiding it until I know exactly if its a must.