如何解决如何使用 NEXUS 配置 GITLAB CI?
我想用 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 Example
试试吧:
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile -P dev -DskipTests
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。