【发布时间】:2020-02-15 19:31:33
【问题描述】:
这是我的管道:
stage('Deploy') {
environment {
MAVEN_HOME = '/usr/share/maven'
JAVA_HOME= '/usr/local/openjdk-8'
}
steps {
rtMavenResolver (
id: 'resolver-unique-id',
serverId: 'my-server-config',
releaseRepo: 'my-repo',
snapshotRepo: 'my-repo'
)
rtMavenDeployer (
id: 'deployer-unique-id',
serverId: 'my-server-config',
releaseRepo: 'my-repo',
snapshotRepo: 'my-repo'
)
rtMavenRun (
pom: 'pom.xml',
goals: 'help:effective-settings',
//goals: 'deploy',
resolverId: 'resolver-unique-id',
deployerId: 'deployer-unique-id'
)
// This works
rtPublishBuildInfo (
serverId: 'my-server-config'
)
我在 jenkins (my-server-config) 上配置了凭据和 URL。我知道它配置正确,因为 rtPublishBuildInfo() 工作并发布到 Artifactory。它使用的用户是一个完整的管理员,所以应该没有权限问题。
这是在容器从属设备中运行的,因此我必须手动设置环境以指向 Maven 和 Java 主目录的位置,以便插件找到它。它正在运行官方的 Maven 镜像
当我尝试部署目标时(确认使用相同的用户凭据在本地工作)我看到此错误:
[main] WARNING org.codehaus.plexus.PlexusContainer - Could not transfer metadata com.mycompany.app:my-app:1.0-SNAPSHOT/maven-metadata.xml from/to snapshots (https://my-tenant.jfrog.io/my-tenant/my-repo): Not authorized
我尝试运行 help:effective-settings 目标并检查 jenkins 输出。看起来它没有使用我的信用?这个插件如何与我在配置中设置的 Jenkins cred 绑定一起工作?它如何将这些信誉传递给 mvn?
Effective user-specific configuration settings:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!-- -->
<!-- Generated by Maven Help Plugin on 2019-10-18T19:04:34Z -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
<!-- -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!-- -->
<!-- Effective Settings for 'root' on 'mypackagepackage-2zbtg-hsxqv' -->
<!-- -->
<!-- ====================================================================== -->
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<localRepository>/root/.m2/repository</localRepository>
<pluginGroups>
<pluginGroup>org.apache.maven.plugins</pluginGroup>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
</settings>
编辑 1
现在我认为该插件完全损坏了我尝试明确地将具有正确凭据的全局设置文件传递给它,但它仍然失败:
rtMavenRun (
pom: 'pom.xml',
//global-settings here is a jenkins secret file with the entire contents of a global settings.xml
goals: '--settings ${global-settings} deploy',
resolverId: 'resolver-unique-id',
deployerId: 'deployer-unique-id'
)
我看到了这个错误:
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-app: Execution default-deploy of goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy failed.: NullPointerException -> [Help 1]
编辑 2
好的,即使这在本地运行良好,我也尝试在我的 pom 中设置部署插件的更新版本:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
现在我从插件中收到 另一个 错误(这仍然可以在本地正常工作):
Caused by: java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors:
The target deployment path 'com/mycompany/app/my-app/1.0-20191018.195756-35/my-app-1.0-20191018.195756-35.pom' does not match the POM's expected path prefix 'com/mycompany/app/my-app/1.0-SNAPSHOT'. Please verify your POM content for correctness and make sure the source path is a valid Maven repository root path. Status code: 40
编辑 3
继续我与这个垃圾 jfrog 插件的史诗般的斗争,我禁用了对本地 repo 的一致性检查,它可以部署但现在我理解了这个错误。它正在转换我的 pom 并将 1.0-SNAPSHOT 变成 1.0-20191018.195756-35 为什么这样做以及如何让它不破坏我的 pom 文件?
编辑 4
我一定是个白痴,否则文档不是很清楚(可能两者兼而有之)。我使用部署目标是因为我想部署。但显然你不用插件来做到这一点——这对我来说很有意义。你 clean 和 install 包,但把它留给插件来部署它,所以它把它放在正确的位置并附加构建信息。使用install 作为目标有效。
【问题讨论】:
标签: maven jenkins artifactory