Jenkins escape sed command

Can anyone escape this sed shell command in a Jenkins groovy script for me?

So difficult.

sh ("""
sed "s/(AssemblyInformationalVersion\(\")(.*)(\")/\1${productVersion}\3/g" 
AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r
""")
+4
source share
2 answers

(""") / (), (\) "escape". , Groovy . , , . , (\\), .

:

sh ("""
sed "s/(AssemblyInformationalVersion\\(\\")(.*)(\\")/\\1${productVersion}\\3/g" 
AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r
""")
+4

, String groovy, "/" "/" , , , .

, linux sed, (, sed .env).

Jenkins Pipeline Groovy:

        String s = "A/B/C"
        your_variable = s.replace("/", "\\/")
        sh "sed -i -e 's/string_to_replace/${your_variable}/g' path/to/file/.env"

. ${your_variable} .

:

echo "Your variable new content: ${your_variable}"

:

Your variable new content: A\/B\/C
+2

Source: https://habr.com/ru/post/1662448/


All Articles