我正在尝试使用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] ERROR 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): 未经授权,ReasonPhrase:未经授权。 - > [帮助1]
只有当我切换到使用Artifactory插件时才会出现错误。
在尝试此操作之前,我确认在Jenkins中正确配置了Maven。像下面这样的东西就可以了:
withMaven(maven: 'Maven 3.3.9') {
sh "mvn -e -B ${args}"
}
执行mvn deploy
会将war文件推送到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。为此,我还尝试将调用包装到configFileProvider块中的rtMaven.run
并将设置传递给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
Artifactory: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>
答案 0 :(得分:1)
在这种情况下,您在Jenkins配置配置系统中指定了Artifactory Server“arty”。在那里,您还需要添加凭据。
如果您不想使用Jenkins配置,则可以对管道中的所有信息进行硬编码
def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password'
或从Jenkins凭据def server = Artifactory.newServer url: 'artifactory-url', credentialsId: 'credential'