[英]'Not authorized' errors after switching from vanilla Maven to Jenkins Artifactory Plugin
我正在尝试使用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从/转移到artifactory-release( https://arty.example.com: 8443 / artifactory / libs-release ):未授权,ReasonPhrase:未授权。 -> [帮助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配置Configure System中指定了Artifactory Server“ arty”。 在那里,您还需要添加凭据。
如果您不想使用Jenkins配置,则可以在管道def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password'
所有信息进行硬编码def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password'
或从Jenkins凭证def server = Artifactory.newServer url: 'artifactory-url', credentialsId: 'credential'
取得凭证def server = Artifactory.newServer url: 'artifactory-url', credentialsId: 'credential'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.