How to use jenkins version number plugin in Jenkinsfile?

橙三吉。 提交于 2020-01-01 18:43:06

问题


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?


回答1:


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.




回答2:


in Jenkinsfile.. try this

env.BN = VersionNumber([
        versionNumberString :'${BUILD_MONTH}.${BUILDS_TODAY}.${BUILD_NUMBER}', 
        projectStartDate : '2017-02-09', 
        versionPrefix : 'v1.'
    ])



回答3:


In stage use the script block to run for version numbering

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


来源:https://stackoverflow.com/questions/48471602/how-to-use-jenkins-version-number-plugin-in-jenkinsfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!