How to use jenkins version number plugin in Jenkin

2019-04-15 20:23发布

Trying this step in Jenkinsfile with "version number plugin" installed:

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

And getting this error:

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

What is correct way to use this plugin in Jenkinsfile?

2条回答
别忘想泡老子
2楼-- · 2019-04-15 20:51

You need to use it as a step.

tag = VersionNumber (versionNumberString: '${BUILD_DATE_FORMATTED, "yyyyMMdd"}-develop-${BUILDS_TODAY}')

Take a look at https://your_jenkins_url.com/pipeline-syntax/ and check all the options for the VersionNumber step in the snipped generator.

查看更多
做个烂人
3楼-- · 2019-04-15 20:58

in Jenkinsfile.. try this

env.BN = VersionNumber([
        versionNumberString :'${BUILD_MONTH}.${BUILDS_TODAY}.${BUILD_NUMBER}', 
        projectStartDate : '2017-02-09', 
        versionPrefix : 'v1.'
    ])
查看更多
登录 后发表回答