繁体   English   中英

如何使用 NEXUS 配置 GITLAB CI?

[英]How can I configure GITLAB CI with NEXUS?

我想用 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 存储库而不是我的关系。

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

MAVEN_CLI_OPTS不是官方的 MAVEN 环境变量,而是推荐的存储重复选项的方式。 您甚至可以在GitLab 示例中看到这一点

试试看嘛:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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