Search code examples
jenkinsjenkins-job-dsl

jenkins job dsl trigger not working for freestyle job


I want to create a freestyle job that runs every minute. I can get it to work with "triggers" not sure what the issue is

job('myjob') {

    // doesnt throw error and doesnt configure trigger
    //triggers { cron "* * * *" }

    // throws error when running
    //triggers { periodic(1) }

    // this works but I want 1 minute not 2 minutes
    // the correct syntax in the UI is just "* * * *" but dsl doesnt seem to like that
    //triggers { cron "H/2 * * * *" }

    steps {
        systemGroovyCommand(""" 
            jenkins.model.Jenkins.instance.getAllItems(jenkins.model.ParameterizedJobMixIn.ParameterizedJob.class).findAll{
              println it
            }
        """)
    }

Solution

  • Cron entries must contain five elements. The proper syntax is

    triggers { cron("* * * * *") }