Maven Nexus 问题 - 403 Forbidden 授权失败

ola*_*tom 5 java nexus maven gitlab gitlab-ci-runner

我们已经讨论这个问题好几天了。

为 Java 应用程序创建了一个 Gitlab CI 管道,从 Maven 和 Nexus 读取依赖项

gitlab 管道被配置为以具有管理员权限的 Nexus 用户身份运行,这已经被多次验证。

但是,当执行 gitlab 管道时,我们收到以下错误:

[ERROR] Failed to execute goal on project hello-component: Could not resolve dependencies for project x.y.z:hello-component:jar:1.6-SNAPSHOT: Failed to collect dependencies at a.b:c:jar:4.5.1132100: Failed to read artifact descriptor for b:c:jar:4.5.1132100: Could not transfer artifact a.b:c:pom:4.5.1132100 from/to maven-snapshots (http://host:8081/repository/maven-snapshots): Authorization failed for http://host:8081/repository/maven-snapshots/a/b/c/4.5.1132100/nidp-4.5.1132100.pom 403 Forbidden -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project hello-component: Could not resolve dependencies for project x.y.z:hello-component:jar:1.6-SNAPSHOT: Failed to collect dependencies at a.b:c:jar:4.5.1132100
Run Code Online (Sandbox Code Playgroud)

我还使用了以下指南:

https://blog.sonatype.com/how-to-use-gitlab-ci-with-nexus
Run Code Online (Sandbox Code Playgroud)

我的 POM 具有以下内容,并在 ci/cd/settings/variables 中配置了环境变量:

     <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.5.1</version>
                    <executions>
                        <execution>
                            <id>default-deploy</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <serverId>maven-snapshots</serverId>
                        <nexusUrl>http://host:8081/repository/maven-snapshots</nexusUrl>
                        <skipStaging>true</skipStaging>
                    </configuration>
                </plugin>
            </plugins>
        </build>

<repositories>
        <repository>
            <id>maven-snapshots</id>
            <url>http://host:8081/repository/maven-snapshots</url>
        </repository>
        <repository>
            <id>maven-releases</id>
            <url>http://host:8081/repository/maven-releases</url>
        </repository>
        <!--repository>
            <id>nexus.local</id>
            <url>$HOME/.m2/repository</url>
        </repository-->
    </repositories>

    <distributionManagement>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://host:8081/repository/maven-snapshots</url>
        </snapshotRepository>
        <repository>
            <id>maven-releases</id>
            <url>http://host:8081/repository/maven-releases</url>
        </repository>
    </distributionManagement>
Run Code Online (Sandbox Code Playgroud)

Gitlab CI 运行器具有以下功能:

image: maven:3.3.9-jdk-8

variables:
  GIT_STRATEGY: clone
  MAVEN_CLI_OPTS: "-s /opt/apache-maven-3.6.3/conf/settings.xml --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=/home/gitlab-runner/.m2/repository"

cache:
  paths:
    - /home/gitlab-runner/.m2/repository/
    - target/

stages:
  - build

CodeBuild:
  stage: build
  script:
   - /opt/apache-maven-3.6.3/bin/mvn $MAVEN_CLI_OPTS -X clean package
  artifacts:
    name: “x—y-component"
    paths:
      - ./target/x—y-component.jar
Run Code Online (Sandbox Code Playgroud)

gitlab ci 服务器上的Setting.xml 具有以下Nexus 用户参考:

maven-snapshots [管理员用户] [管理员密码]

任何帮助将不胜感激。

谢谢

小智 0

不确定是否仍然需要帮助,但似乎您没有向用于部署/解决依赖关系的用户角色授予必要的权限。请授予角色 nx-repository-view- - -* 权限。对其进行测试,然后您可以根据需要缩小范围。