如何正确地转义Jenkins文件中的sed命令
我可以从命令行运行此命令,以获取GitHub repo中最新版本的值: 卷曲——沉默”https://api.github.com/repos/MyOrg/MyRepo/releases/latest“|grep”tag_name“| sed-E's/”([^“]+)”/\1/” 我想在Jenkins文件中使用它,但我似乎无法正确地避开特殊字符如何正确地转义Jenkins文件中的sed命令,jenkins,groovy,sed,jenkins-pipeline,Jenkins,Groovy,Sed,Jenkins Pipeline,我可以从命令行运行此命令,以获取GitHub repo中最新版本的值: 卷曲——沉默”https://api.github.com/repos/MyOrg/MyRepo/releases/latest“|grep”tag_name“| sed-E's/”([^“]+)”/\1/” 我想在Jenkins文件中使用它,但我似乎无法正确地避开特殊字符 pipeline { agent any stages { stage('Test') { st
pipeline {
agent any
stages {
stage('Test') {
steps {
sh """
latest=`curl --silent \\\"https://api.github.com/repos/MyOrg/MyRepo/releases/latest\\\"|
grep \\\"tag_name\\\"|
sed -E \\\'s/.*\\\"([^\\\"]+)\\\".*/\1/\\\'`
""".stripIndent()
}
}
}
}
在管道中运行时,出现以下错误:
[管道]上海
- 卷曲——沉默”https://api.github.com/repos/MyOrg/MyRepo/releases/latest"
- grep“tag_name”
- sed-E's/*” sed:-e表达式#1,字符1:未知命令:`'
$(command_1 | command_2 | command_3)
另外,在shell命令的开头添加:
set -x;
您将在控制台输出中获得调试输出(可能)。然后,您应该看到脚本是如何被评估的