简体   繁体   中英

Jenkins Job DSL does not take parameters

I have a Jenkins seed DSL job:

job("cronjob/${ACTION}_${ENVRIONMENT}_environment_CRONJOB") {
    scm {
      git('https://git_user@github.com/abc-Data/devops.git','*/develop')
    }
  triggers {
    scm("${SCHEDULE}")
  }
    steps {
      ansiblePlaybook("ansible/scripts/ansible-${ACTION}.yml") {
        inventoryPath("/etc/ansible/hosts")
        credentialsId("usercred")
        extraVars {
            extraVar('environment_name',"${ENVRIONMENT}",false)
        }

      }
    }
}

ACTION, ENVIRONMENT and SCHDULE are parameters.

ACTION can have values of create or remove , and I have two ansible playbooks ansible-create.yml and ansible-remove.yml .

When I run the sseed job, I got the following error:

ERROR: (unknown source) No signature of method: javaposse.jobdsl.dsl.helpers.step.StepContext.ansiblePlaybook() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, script$_run_closure1$_closure4$_closure5) values: [ansible/scripts/ansible-create.yml, ...]
Finished: FAILURE

The ansiblePlaybook("ansible/scripts/ansible-${ACTION}.yml") does not work with the variable ACTION.

If I hard code the the script name in ansiblePlaybook , the seed job will create a new job. The other two variables work fine in the DSL script.

What did I miss here?

Thanks!

As @daggett suggested above, I changed the code as below:

job("cronjob/${ACTION}_${ENVRIONMENT}_environment_CRONJOB") {
    scm {
      git('https://git_user@github.com/abc-Data/devops.git','*/develop')
    }
  triggers {
    scm("${SCHEDULE}")
  }
    steps {
      ansiblePlaybook("ansible/scripts/ansible-${ACTION}.yml" as String) {
        inventoryPath("/etc/ansible/hosts")
        credentialsId("usercred")
        extraVars {
            extraVar('environment_name',"${ENVRIONMENT}",false)
        }

      }
    }
}

It works as expect and create a new job with the use entered variable values. Thanks to you again @daggett!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM