【发布时间】:2018-07-20 02:33:02
【问题描述】:
我正在尝试使用 Jenkins Artifactory 插件来运行 Maven 构建并将 buildInfo 发布到我的 Artifactory 实例。所有这些都在 Jenkinsfile 中编写脚本,并作为管道构建执行。代码如下:
def server
def buildInfo
def rtMaven
server = Artifactory.server('arty')
rtMaven = Artifactory.newMavenBuild()
rtMaven.tool = 'Maven 3.3.9' // Tool name from Jenkins configuration
rtMaven.deployer releaseRepo: 'ci-test', snapshotRepo: 'ci-test', server: server
rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot', server: server
rtMaven.deployer.deployArtifacts = false // Disable artifacts deployment during Maven run
buildInfo = Artifactory.newBuildInfo()
rtMaven.run pom: 'pom.xml', goals: "-e -B install".toString(), buildInfo: buildInfo
server.publishBuildInfo buildInfo
这会导致很多错误,类似下面的
[main] 错误 org.apache.maven.cli.MavenCli - 插件 org.apache.maven.plugins:maven-install-plugin:2.4 或其之一 无法解析依赖项:无法读取工件描述符 对于 org.apache.maven.plugins:maven-install-plugin:jar:2.4: 不能 传输工件 org.apache.maven.plugins:maven-plugins:pom:23 从/到工件发布 (https://arty.example.com:8443/artifactory/libs-release): 未授权,原因短语:未授权。 -> [帮助 1]
只有当我切换到使用 Artifactory 插件时才会出现错误。
在尝试此操作之前,我确认在 Jenkins 中正确配置了 Maven。像下面这样的东西就可以了:
withMaven(maven: 'Maven 3.3.9') {
sh "mvn -e -B ${args}"
}
执行mvn deploy 会将战争文件推送到 Artifactory。
我怀疑这与我的 Maven 设置有关。我已经验证 Maven 作为 Jenkins 工具可以正常工作。我可以在 .m2 文件夹中提供一个 settings.xml,或者通过 Jenkins 提供一个配置文件,例如:
withMaven(maven: 'Maven 3.3.9', mavenSettingsConfig: '10452c41-5bdb-4d11-b711-9b2d00751c2e')
这两个选项都有效(如果我删除它们会导致预期的失败)。
我注意到,Artifactory 插件允许我指定 Jenkins 工具的名称 (Maven 3.3.9),但 不是 mavenSettingsConfig。为此,我还尝试将对 rtMaven.run 的调用包装在 configFileProvider 块中并将设置传递给 mvn:
configFileProvider(
[configFile(fileId: '10452c41-5bdb-4d11-b711-9b2d00751c2e', variable: 'MAVEN_SETTINGS')]) {
rtMaven.run pom: 'pom.xml', goals: "-s $MAVEN_SETTINGS -e -B install".toString(), buildInfo: buildInfo
server.publishBuildInfo buildInfo
}
这也被证明是不成功的。
此时,任何建议都会有所帮助!
版本信息:
詹金斯:2.89.3
Jenkins Artifactory 插件:2.13.1
Maven:3.3.9
神器:5.8.3 Pro
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<localRepository>/home/jenkins-user/.m2/repository</localRepository>
<servers>
<server>
<username>artyuser</username>
<password>ARTYPASSHASH</password>
<id>central</id>
</server>
<server>
<username>artyuser</username>
<password>ARTYPASSHASH</password>
<id>snapshots</id>
</server>
<server>
<username>artyuser</username>
<password>ARTYPASSHASH</password>
<id>arty</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>https://arty.example.com:8443/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>https://arty.example.com:8443/artifactory/libs-snapshot</url>
</repository>
<repository>
<snapshots />
<id>arty</id>
<name>ci-test</name>
<url>https://arty.example.com:8443/artifactory/ci-test</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>https://arty.example.com:8443/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>https://arty.example.com:8443/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
【问题讨论】:
-
您是否在 Jenkins 中为 Artifactory 插件配置添加了凭据?
-
否 - 我在我的 Maven settings.xml 中指定了用户凭据(我认为插件在调用 Maven 时正在使用它?)。不过,我现在就试试这个。
-
不,它没有,您必须在 Jenkins > 配置系统中指定凭据,在其中添加“arty”或在管道中明确指定
def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password' -
哦,呵呵!事后看来,我现在看到 - 我已经指定了服务器详细信息,为什么我希望从 settings.xml 中提取凭据,而没有其他内容......?请发表您的最后评论作为答案,我会接受。谢谢!
标签: maven jenkins jenkins-pipeline artifactory