防止用单引号将Jenkinsfile中的参数括起来

abithluo  于 2022-10-06  发布在  Jenkins
关注(0)|答案(0)|浏览(113)

在我的Jenkinsfile(Jenkins运行管道)中,我想执行一个命令:

def lastTagV1 = sh(script: 'git describe --abbrev=0 --tags', returnStdout: true).trim()

// same result
def lastTagV2 = sh(script: '''git describe --abbrev=0 --tags''', returnStdout: true).trim()

// same result
def lastTagV3 = sh(script: "git describe --abbrev=0 --tags", returnStdout: true).trim()

但在执行此步骤时,Jenkins(或bash)用单引号将缩写括起来,并且命令失败:

+ git describe '--abbrev=0' --tags
fatal: No names found, cannot describe anything.

也许还有另一种解决方案可以从git命令获取最后一个标记,但我想了解为什么以及如何解决这个单引号问题。

该命令即使使用单引号也可以在Jenkins上使用,但之前需要获取标记,否则它会失败,如上所述。

sh 'git fetch --tags'
def lastTag = sh(script: 'git describe --abbrev=0 --tags', returnStdout: true).trim()

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题