简体   繁体   中英

Jenkins/Groovy- Job DSL plugin - git() vs git{}

As per Job DSL plugin API documentation for Git , there are two forms to use it:

  1. git('repo_url')
  2. git {...} //with lot of additional options

What is the difference between these two approaches?
One is a method call and the other one is calling a closure?

As per this article , I guess both forms are calling a Groovy closure + some Groovy syntactic sugar.

One is a method call and the other one is calling a closure?

Both are method calls - but the first takes a string on git - while the latter takes a closure as argument.

As per the api-doc api you shared above, it looks like the first one - git {} - provides maximum options to setup the SCM context - that includes an option to manipulate directly the generated XML through configure closure. All the others seem to be the variants of this option with the last argument as the configure closure.

If the last parameter of a method call is a closure, it can be passed outside the parentheses

Yes, you are right. And, if the closure is the only method argument, then method can be called with just that and without any parentheses. That's exactly what the first call is about git {}

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