Jenkins管道多线外壳具有转义字符

dev*_*rts 6 jenkins jenkins-pipeline

我遇到了一个管道脚本的奇怪问题.我有一个多行sh blob喜欢

sh """
   git tag -fa \\"${version}\\" -m \\"Release of ${version}\\"
"""
Run Code Online (Sandbox Code Playgroud)

而这在某种程度上运行:

+ git tag -fa '"1.0-16-959069f'
error: Terminal is dumb, but EDITOR unset
Please supply the message using either -m or -F option.
Run Code Online (Sandbox Code Playgroud)

所以它放弃了-m和消息.我试过单逃,双逃,似乎没什么用.

dev*_*rts 2

我不知道为什么这有效,但确实如此

def tagGithub(String version) {
    def exec = """
    git tag -d ${version} || true
    git push origin :refs/tags/${version}

    # tag new version
    git tag -fa ${version} -m "Release of ${version}"
    git push origin --tags
    """

    sh exec
}
Run Code Online (Sandbox Code Playgroud)

内联詹金斯常规插值的某些内容似乎被破坏了,在另一个变量中进行插值然后执行它有效

  • 所以我计算“版本”的方式,它在末尾有一个新的行字符。所以我添加了 `version.trim()` 并且它开始工作。 (2认同)