job-dsl 生成的 Jenkins 作业没有选择默认的 Maven 设置

Jenkins job generated by job-dsl are not picking up default Maven settings

我正在 运行在 Windows Server 2012 上安装 Jenkins 2.25 服务器。目前我们正在使用 Maven Integration Plugin 2.12.1 和 Job DSL Plugin 1.57。

我已经为我们服务器上的大约 200 个现有作业编写了 DSL 脚本。

对于任何使用 Maven 的工作,无论是作为构建步骤还是作为实际的 Maven,我都遇到了一个非常令人沮丧的问题。当我 运行 生成的作业时,它们失败并显示以下输出。

12:17:12 [ERROR] Failed to execute goal com.googlecode.maven-download-    plugin:download-maven-plugin:1.3.0:wget (default) on project myprojecy: The     parameters 'url' for goal com.googlecode.maven-download-plugin:download-maven-plugin:1.3.0:wget are missing or invalid -> [Help 1]
12:17:12 [ERROR] 
12:17:12 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
12:17:12 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
12:17:12 [ERROR] 
12:17:12 [ERROR] For more information about the errors and possible solutions, please read the following articles:
12:17:12 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

最初我们认为我们将问题确定为我们缺少 XML 片段,甚至认为这些设置看起来应该在 UI.

<settings class="jenkins.mvn.DefaultSettingsProvider"/> 
<globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/> 
<injectBuildVariables>false</injectBuildVariables>

因此将此添加到脚本中:

configure { node ->
node / settings (class: 'jenkins.mvn.DefaultSettingsProvider') {
}
node / globalSettings (class: 'jenkins.mvn.DefaultGlobalSettingsProvider') {
}
node / injectBuildVariables ('false') {
}
}

但是当我尝试 运行 时作业仍然失败,即使 XML 现在按预期包含了这个片段。

现在我无法解决的两件非常奇怪的事情显然是相关的。首先,在作业失败后,如果我为作业手动 select "configure",然后保存它(即不进行任何实际更改),作业 运行 永远都很好(直到种子工作我们 运行 然后它再次失败)。

其次,在我 运行 种子作业之后的作业配置历史记录中,我看到了系统用户下的种子作业 运行s 时所做的更改。然而,在几秒钟内,每次都会在我的用户名下记录另一个配置更改,尽管我没有对作业配置进行任何更改 - 顺便说一下,这与我保存作业而不进行更改无关,它立即发生。

我应该补充一点,进一步检查向我表明 Maven 有一些默认设置未应用于我的 DSL 生成的作业。将 -X 开关添加到 Maven 目标时,我可以看到有关这些作业在哪里失败的更多信息。输出是:

 15:06:31 [DEBUG] Goal:          com.googlecode.maven-download-plugin:download-maven-plugin:1.3.0:wget (default) 
 15:06:31 [DEBUG] Style:         Regular 
 15:06:31 [DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?> 
 15:06:31 <configuration> 
 15:06:31   <cacheDirectory>${download.cache.directory}</cacheDirectory> 
 15:06:31   <checkSignature default-value="false">${checkSignature}</checkSignature> 
 15:06:31   <failOnError default-value="true"/> 
 15:06:31   <outputDirectory default-value="${project.build.directory}">D:\data\jenkins\workspace\project\target</outputDirectory> 
 15:06:31   <outputFileName>${jarsigner.keystore.filename}</outputFileName> 
 15:06:31   <overwrite>${download.overwrite}</overwrite> 
 15:06:31   <readTimeOut default-value="0"/> 
 15:06:31   <retries default-value="2"/> 
 15:06:31   <session>${session}</session> 
 15:06:31   <skip default-value="false">${download.plugin.skip}</skip> 
 15:06:31   <skipCache default-value="false"/> 
 15:06:31   <unpack default-value="false">false</unpack> 
 15:06:31   <url>${jarsigner.keystore.url}</url> 
 15:06:31 </configuration>

在作业成功 运行 的地方(post 假配置更改)其中一些字段已满,例如密钥库的 URL。这显然是问题所在,但我不知道该怎么办。据我所知,应该通过在 groovy 中包含上面的配置块来解决这个问题,但不知何故我的工作缺少这个(但他们在再次保存工作后没有更改就拥有它)。

谁能看出我做错了什么?

问题是 XML 中自动生成的代码:

<jvmOptions></jvmOptions>

似乎尽管它是空的,但它会覆盖所有默认的 Maven 选项,但是当作业再次保存时,它会被删除,因为它是空的。通过将此添加到 groovy 脚本来解决:

configure({
            it.remove(it / 'jvmOptions')
        })

这似乎是 DSL 中的错误,但令人惊讶的是,我和我的同事一直找不到任何关于此的信息。无论如何,以上为我解决了这个问题。