简体   繁体   English

如何使用 groovy 脚本替换 jenkins 管道中的字符串

[英]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.请给我一个解决方案。

'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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM