Reputation: 437
I want to create a pipeline with Gitlab CI to compile a maven project.
First, I create a .m2
folder in root of my project and I add the settings.xml
config file.
My project look like :
Project
- module1
- module2
- module3
- pom.xml
- .m2
-setting.xml
In the settings file I do this :
<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>
In my pom.xml
I have this repository :
<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>
And in my .gitlab-ci.yml
I have :
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
When I push this config to gitlab, the pipeline start with a failure message :
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
It seems that gitlab try to connect to the default maven repository and not to my nexus.
How can I tell gitlab to call the nexus repository and not the default repository ?
Upvotes: 2
Views: 8615
Reputation: 4764
MAVEN_CLI_OPTS
is not an official MAVEN environment variable, but the recommended way to store repeating options. you can even see this in the GitLab Example
Just try:
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile -P dev -DskipTests
Upvotes: 2