如何使用 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 存储库而不是我的 nexus。
如何告诉 gitlab 调用 nexus 存储库而不是默认存储库?
MAVEN_CLI_OPTS
不是官方的 MAVEN 环境变量,而是推荐的存储重复选项的方式。你甚至可以在 GitLab Example
中看到这个
试一试:
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile -P dev -DskipTests
我想用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_CLI_OPTS
不是官方的 MAVEN 环境变量,而是推荐的存储重复选项的方式。你甚至可以在 GitLab Example
试一试:
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile -P dev -DskipTests