Dev*_*ops 2 groovy jenkins jenkins-pipeline
如何在詹金斯管道中使用 groovy 用“#”替换文本文件中出现的所有“\n”
这应该有效。在 Groovy 中使用查找运算符 ~
def parsedtext = readFile("input.groovy").replaceAll(~/\n/, "#")
writeFile file: "output.groovy", text: parsedtext
Run Code Online (Sandbox Code Playgroud)
编辑 如果您使用的是声明式管道语法,以下是工作代码。
pipeline {
agent any
stages {
stage ('Print'){
steps {
script {
def inptext = readFile file: "1.groovy"
inptext = inptext.replaceAll(~/\n/, "#")
writeFile file: "2.groovy", text: inptext
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9203 次 |
最近记录: |