[英]How to replace string in jenkins pipeline using groovy script
I'm trying to replace a string in jenkins pipeline using groovy script the string is我正在尝试使用 groovy 脚本替换 jenkins 管道中的字符串,该字符串是
input : prakash/annam/devops输入:prakash/annam/devops
expected output : prakash/\\annam/\\devops预期输出:prakash/\\annam/\\devops
I'm using this sed -i 's#/#/\\#g' .我正在使用这个 sed -i 's#/#/\\#g' 。 Unfortunately it is working in shell scripting but not in jenkins pipeline.
不幸的是,它在 shell 脚本中工作,但不在 jenkins 管道中。 Please give me a solution.
请给我一个解决方案。
str = str.replaceAll( '/', '/\\' )
What you can do with strings in groovy:你可以用 groovy 中的字符串做什么:
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html https://docs.oracle.com/javase/8/docs/api/java/lang/String.html
https://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/String.html https://docs.groovy-lang.org/latest/html/groovy-jdk/java/lang/String.html
'prakash/annam/devops'.replaceAll("/", "/\\\\")
will do what you want.会做你想做的。 Refer here: https://stackoverflow.com/a/6377310/3355860
请参阅此处: https : //stackoverflow.com/a/6377310/3355860
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.