jenkinsjenkins-pipelinejenkins-groovyjcasc

Cron job in Jenkins with choice params doesn't work


I am trying to write a jenkins cron job with some paratmers of type choiceParam() and it doent work together.

How do i Have choce params and run the job in every 6 hours?

I am trying do it via jCASC, where i have a .groovy which having the script below, while it runs .jenikins file.

    properties {
        pipelineTriggers {
            triggers {
                cron {
                    spec('* h/6 * * *')
                }
            }
        }
    }
    
    parameters {
        stringParam('JENKINS_FILE_BRANCH', 'branch name', 'The Branch with the Jenkins File')
        choiceParam('SERVICE_NAME', ['service1' 'serivce 2'], 'Select a service to check the status for')
        choiceParam('DC', ['DC1', 'CD2'], 'Select a service to check the status for')
    }

and when i push it it throws the error as below

ERROR: Could not instantiate {spec= h/6 * * } for hudson.triggers.TimerTrigger: java.lang.reflect.InvocationTargetException


Solution

  • A corrected version of your syntax would be spec('* H/6 * * *'). This will trigger the job every 6 hours, but the exact minute will vary to help balance the load.