簡體   English   中英

從香草Maven切換到Jenkins Artifactory插件后出現“未授權”錯誤

[英]'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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM