Search code examples
jenkinsgroovyjenkins-job-dsl

Jenkins DSL Syntax: Run Periodically With Parameters


I am trying to run a Jenkins DSL script to create jobs that build periodically with multiple parameters. So far, all I have found is parameterizedCron, but I believe that is for Jenkins Pipeline. Is there something similar for Jenkins DSL?

triggers {
    parameterizedCron('''
        H 0 * * * % Browser=Chrome;Environment=Dev;TestCase=Student_Login
        H 0 * * * % Browser=Firefox;Environment=Dev;TestCase=Student_Login
        H 0 * * * % Browser=Safari;Environment=Dev;TestCase=Student_Login
        H 0 * * * % Browser=Chrome;Environment=Test;TestCase=Student_Login
        H 0 * * * % Browser=Firefox;Environment=Test;TestCase=Student_Login
        H 0 * * * % Browser=Safari;Environment=Test;TestCase=Student_Login
        ''')
}

Solution

  • I have found this answer.

    This specifically works for the Jenkins Job DSL:

    triggers {
        parameterizedTimerTrigger {
            parameterizedSpecification('''
                H 0 * * * % Browser=Chrome;Environment=Dev;TestCase=${testCaseName}
                H 0 * * * % Browser=Firefox;Environment=Dev;TestCase=${testCaseName}
                H 0 * * * % Browser=Safari;Environment=Dev;TestCase=${testCaseName}
                H 0 * * * % Browser=Chrome;Environment=Test;TestCase=${testCaseName}
                H 0 * * * % Browser=Firefox;Environment=Test;TestCase=${testCaseName}
                H 0 * * * % Browser=Safari;Environment=Test;TestCase=${testCaseName}
            ''')
        }
    }
    

    See DSL for triggering cron with a parameter. I have defined the parameter in the job above but unable to pass it in the cron using dsl scripts