简体   繁体   English

从香草Maven切换到Jenkins Artifactory插件后出现“未授权”错误

[英]'Not authorized' errors after switching from vanilla Maven to Jenkins Artifactory Plugin

I am trying to use the Jenkins Artifactory Plugin to run a Maven build and publish the buildInfo to my Artifactory instance. 我正在尝试使用Jenkins Artifactory插件来运行Maven构建并将buildInfo发布到我的Artifactory实例。 All of this is scripted in a Jenkinsfile and executed as a pipeline build. 所有这些都在Jenkinsfile中编写脚本,并作为管道构建执行。 Code as follows: 代码如下:

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

This results in many errors, similar to the following 这将导致许多错误,类似于以下内容

[main] ERROR org.apache.maven.cli.MavenCli - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.4: Could not transfer artifact org.apache.maven.plugins:maven-plugins:pom:23 from/to artifactory-release ( https://arty.example.com:8443/artifactory/libs-release ): Not authorized , ReasonPhrase: Unauthorized. [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:未授权。 -> [Help 1] -> [帮助1]

It is only when I switch to using the Artifactory plugin that the errors begin. 只有当我切换到使用Artifactory插件时,错误才开始。

Before attempting this, I confirmed that Maven is correctly configured within Jenkins. 在尝试此操作之前,我确认在Jenkins中正确配置了Maven。 Something like the following works just fine: 像下面这样的东西就可以了:

withMaven(maven: 'Maven 3.3.9') {
    sh "mvn -e -B ${args}"
}

Doing a mvn deploy will push the war file up to Artifactory. 进行mvn deploy会将战争文件推向Artifactory。

I suspected it had something to do with my Maven settings. 我怀疑这与我的Maven设置有关。 I have verified that Maven is working correctly as a Jenkins tool. 我已经验证了Maven作为Jenkins工具可以正常工作。 I can supply a settings.xml in the .m2 folder, or a config file via Jenkins, something like: 我可以在.m2文件夹中提供settings.xml,也可以通过Jenkins提供配置文件,例如:

withMaven(maven: 'Maven 3.3.9', mavenSettingsConfig: '10452c41-5bdb-4d11-b711-9b2d00751c2e') 

Both options work (and cause expected failures if I remove them). 这两个选项均有效(如果我将其删除,则会导致预期的故障)。

What I have noticed is that the Artifactory Plugin allows me to specify the name of the Jenkins Tool ( Maven 3.3.9 ) but not the mavenSettingsConfig. 我注意到的是Artifactory插件允许我指定Jenkins工具( Maven 3.3.9 )的名称,但不能指定mavenSettingsConfig。 To that end I also attempted wrapping the call to rtMaven.run in a configFileProvider block and passing the settings to mvn: 为此,我还尝试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
    }

This too proved unsuccessful. 这也被证明是不成功的。

At this point, any suggestions would be helpful! 此时,任何建议都将有所帮助!

Version info: 版本信息:
Jenkins: 2.89.3 詹金斯:2.89.3
Jenkins Artifactory Plugin: 2.13.1 Jenkins Artifactory插件:2.13.1
Maven: 3.3.9 Maven:3.3.9
Artifactory: 5.8.3 Pro 人工工厂:5.8.3 Pro

settings.xml 的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>

In this case you specified your Artifactory Server "arty" in Jenkins configuration Configure System . 在这种情况下,您在Jenkins配置Configure System中指定了Artifactory Server“ arty”。 There you also need to add credentials. 在那里,您还需要添加凭据。

If you don't want to use Jenkins configuration you can hardcode all information in pipeline def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password' 如果您不想使用Jenkins配置,则可以在管道def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password'所有信息进行硬编码def server = Artifactory.newServer url: 'artifactory-url', username: 'username', password: 'password'

Or take credentials from Jenkins Credentials def server = Artifactory.newServer url: 'artifactory-url', credentialsId: 'credential' 或从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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM