【问题标题】:How can I configure GITLAB CI with NEXUS?如何使用 NEXUS 配置 GITLAB CI?
【发布时间】:2021-05-24 15:36:32
【问题描述】:

我想用 Gitlab CI 创建一个管道来编译一个 maven 项目。

首先,我在项目的根目录中创建一个.m2 文件夹,然后添加settings.xml 配置文件。 我的项目看起来像:

Project
 - module1
 - module2
 - module3
 - pom.xml
 - .m2
     -setting.xml

在设置文件中我这样做:

<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">
  <servers>
    <server>
      <id>nichefactory-releases</id>
      <username>user</username>
      <password>password</password>
    </server>
    <server>
      <id>nichefactory-snapshots</id>
      <username>user</username>
      <password>password</password>
    </server>
  </servers>
  
    <profiles>
        <profile>
            <id>nexus</id>
            <properties>
                <env>dev</env>
                <flex.debug>true</flex.debug>
            </properties>

            <repositories>
                <repository> 
                    <id>nichefactory</id>
                    <name>NicheFactory Repository</name>
                    <url>http://my-nexus:8081/nexus/content/groups/public</url>
                </repository>
            </repositories>
        </profile>
    </profiles>
</settings> 

在我的pom.xml 我有这个存储库:

<distributionManagement>
    <!-- Publish the versioned releases to nexus -->
    <repository>
        <id>nichefactory-releases</id>
        <name>Niche Factory Repository (RELEASE)</name>
        <url>http://my-nexus:8081/nexus/content/repositories/releases</url>
    </repository>

    <!-- Publish the snapshot release to nexus -->
    <snapshotRepository>
        <id>nichefactory-snapshots</id>
        <name>Niche Factory Repository (SNAPSHOTS)</name>
        <url>http://my-nexus:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

在我的.gitlab-ci.yml 我有:

image: maven:latest

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
  MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"

build:
    stage: build
    script: 
        - mvn compile -P dev -DskipTests

当我将此配置推送到 gitlab 时,管道以失败消息开始:

Failure to find apps:pom:version in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 4, column 10

似乎 gitlab 尝试连接到默认的 maven 存储库而不是我的 nexus。

如何告诉 gitlab 调用 nexus 存储库而不是默认存储库?

【问题讨论】:

标签: maven gitlab gitlab-ci nexus


【解决方案1】:

MAVEN_CLI_OPTS 不是官方的 MAVEN 环境变量,而是推荐的存储重复选项的方式。你甚至可以在GitLab Example看到这个

试试吧:

build:
    stage: build
    script: 
        - mvn $MAVEN_CLI_OPTS compile -P dev -DskipTests

【讨论】:

  • 它的工作!谢谢
猜你喜欢
  • 2018-01-27
  • 1970-01-01
  • 1970-01-01
  • 2016-06-24
  • 1970-01-01
  • 2020-10-27
  • 2017-04-08
  • 2018-05-12
  • 2023-01-13
相关资源
最近更新 更多