Jenkins/Groovy- 作业 DSL 插件 - git() 与 git{}

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

根据Job DSL plugin API documentation for Git,有两种形式可以使用它:

  1. git('repo_url')
  2. git {...} //有很多附加选项

这两种方法有什么区别?
一个是方法调用,另一个是调用闭包?

根据 this article,我猜这两种形式都在调用一个 Groovy 闭包 + 一些 Groovy 语法糖。

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

两者都是方法调用 - 但第一个在 git 上接受一个字符串 - 而后者接受一个闭包作为参数。

根据您在上面分享的 api-doc api,它看起来像第一个 - git {} - 提供了设置 SCM 上下文的最大选项 - 包括一个选项通过 configure 闭包直接操作生成的 XML。所有其他似乎都是此选项的变体,最后一个参数是 configure 闭包。

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

是的,你是对的。而且,如果闭包是唯一的方法参数,那么可以只用闭包调用方法而无需任何括号。这正是第一个电话的内容 git {}