Search code examples
jenkins-pipelinejenkins-job-dsl

pass variable from parameterizedCron to the stage in jenkins DSL script


triggers {
        parameterizedCron('''0 */2 * * * %APPLICATION_ID=41''')
    } 
stages{
    ......
    stage('pass cron variable to this stage') {
    **????How to get my APPLICATION_ID here?????**   
    }
}

I want to pass the cron APPLICATION_ID from parameterizedCron to stage as mentiond above


Solution

  • The % sign needs to be separated:

    triggers {
            parameterizedCron('0 */2 * * * % APPLICATION_ID=41')
        } 
    

    You need to have a parameter named APPLICATION_ID:

    parameters {
            string(name: 'APPLICATION_ID', defaultValue: '1', description: 'Application ID')
        }
    

    You can then address the parameter as params.APPLICATION_ID. This will be string. If you need to make an int out of it, you need to convert it into int.