如何在 Jenkinsfile 中使用 jenkins 版本号插件?

Dmi*_*lin 2 plugins version jenkins jenkins-pipeline

在安装了“版本号插件”的 Jenkinsfile 中尝试此步骤:

    stage("Build") {
        echo "Building..."
        TAG = ${BUILD_DATE_FORMATTED, "yyyyMMdd"}-develop-${BUILDS_TODAY}
        sh "docker build -t $IMAGE:$TAG ."
    }
Run Code Online (Sandbox Code Playgroud)

并收到此错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 15: unexpected token: BUILD_DATE_FORMATTED @ line 15, column 15.
           TAG=${BUILD_DATE_FORMATTED, "yyyy-MM-dd"}-develop-${BUILDS_TODAY}
                 ^
1 error
Run Code Online (Sandbox Code Playgroud)

在 Jenkinsfile 中使用这个插件的正确方法是什么?

小智 7

您需要将其用作步骤。

tag = VersionNumber (versionNumberString: '${BUILD_DATE_FORMATTED, "yyyyMMdd"}-develop-${BUILDS_TODAY}')
Run Code Online (Sandbox Code Playgroud)

查看https://your_jenkins_url.com/pipeline-syntax/并检查剪切生成器中 VersionNumber 步骤的所有选项。