来自私有包注册表的 Gitlab CI/CD Maven 依赖项:找不到工件

Fél*_*iel 5 maven gitlab-ci

社区。

我有一个 Maven 包注册表托管在属于某个组的项目中。在该注册表中,我使用个人访问令牌手动上传了一个工件(pom 和 jar 文件)。

我有一个项目使用该包注册表中的该工件。因此,当我尝试执行测试阶段时,它失败并出现以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get (default-cli) on project docker_receiver: Couldn't download artifact: org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact transparent_coach:maven_registry:jar:1.0.0 in gitlab-maven (https://gitlab.com/api/v4/projects/23241686/packages/maven)

这是我正在运行的测试阶段:

test:
  stage: test
  allow_failure: false
  tags:
    - docker
    - dind
  script:
    - mvn --version
    - echo "$TC_GITLAB_AUTH_SETTINGS" > settings.xml
    - mvn dependency:get -Dartifact=transparent_coach:maven_registry:1.0.0
    - mvn clean verify
Run Code Online (Sandbox Code Playgroud)

settings.xml文件存在,并且包含正确的结构,其个人令牌与我用于将工件上传到注册表的个人令牌相同。注册表和工件的参数pom.xml是正确的:

<dependency>
  <groupId>transparent_coach</groupId>
  <artifactId>maven_registry</artifactId>
  <version>1.0.0</version>
</dependency>

#----------------------

<repositories>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/23241686/packages/maven</url>
  </repository>
</repositories>

<distributionManagement>
  <repository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/23241686/packages/maven</url>
  </repository>

  <snapshotRepository>
    <id>gitlab-maven</id>
    <url>https://gitlab.com/api/v4/projects/23241686/packages/maven</url>
  </snapshotRepository>
</distributionManagement>
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

Von*_*onC 1

一个类似的线程提到:

最后我发现需要先进行身份验证。这只是错误的错误消息。

确保您ci_settings.xml的项目中有用于mvn命令的-s ci_settings.xml.

还可以尝试使用 Maven 命令中的选项提高 Maven 日志级别,以获取有关出现问题的更详细信息-X,这将启用调试输出,如下所示:

- mvn --settings ci_settings.xml -X dependency:get -Dartifact=transparent_coach:maven_registry:1.0.0
Run Code Online (Sandbox Code Playgroud)

--settings ci_settings.xml是为了确保您使用的是ci_settings.xml您认为的东西,而不是默认的一套。您可以添加一个步骤来 cat(显示)其内容,以确认其中指定的 URL 是否正确。并确保 URL ( 23241686) 中的项目 ID 正确。

如上所述,身份验证应该设置为ci_settings.xml(我从中得到启发ci_settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpConfiguration>
          <all>
            <usePreemptive>true</usePreemptive>
          </all>
        </httpConfiguration>
      </configuration>
      <username>oauth2</username>
      <password>${env.CI_PERSONAL_ACCESS_TOKEN}</password>
    </server>
  </servers>
</settings>
Run Code Online (Sandbox Code Playgroud)