【问题标题】:Spring Boot: Jenkins removes escaped double quote character from commandsSpring Boot:Jenkins 从命令中删除转义的双引号字符
【发布时间】:2020-07-03 08:37:25
【问题描述】:

我正在为我的 Spring Boot 项目在 Jenkins 上运行作业,最近我遇到了一个问题,Jenkins 正在从它应该运行的命令中删除双引号。不管它是在 Gradle 作业还是管道中,都将删除转义的双引号。示例:

Gradle 工作:

proc = "git log --pretty=format:\"%cd - ${tag} (backend) - %s \" -${distance} --no-merges --date=short".execute()

在本地工作正常,但在 Jenkins 上失败并出现错误:fatal: ambiguous argument '(backend)': unknown revision or path not in the working tree.

Jenkins 流水线:

sh "git log --pretty=format:\"%cd - ${tag} (backend) - %s \" -${distance} --no-merges --date=short"

失败并出现语法错误:“(”意外,这归结为与我通过此实验确定的相同:

sh "echo git log --pretty=format:\"%cd - ${tag} (backend) - %s \" -${distance} --no-merges --date=short"

这将返回不带转义双引号的命令:

git log --pretty=format:%cd - 2.0.4(后端)- %s -8 --no-merges --date=short

有人知道如何解决吗?谢谢!

【问题讨论】:

    标签: java jenkins gradle jenkins-pipeline gradlew


    【解决方案1】:

    我无法强迫 Jenkins 使用双引号。我在 Jenkinsfile 中找到了关于转义字符的指南:

    https://gist.github.com/Faheetah/e11bd0315c34ed32e681616e41279ef4

    然而,即使命令似乎有双引号,它仍然会失败,就好像它没有双引号一样。

    我最终将命令写入文件并像这样从 Jenkins 运行它:

    def command = $/echo 'cd logs/backend/ && git log --pretty=format:"%cd - ${tag} (backend) - %s" -${distance} --no-merges --date=short > src/main/resources/changeLog.txt' > cmd/$
    sh command
    sh "./cmd"
    

    【讨论】:

      【解决方案2】:

      您可能需要使用双反斜杠来转义引号:

      \\"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多