Reputation: 13
I have several GitLab projects within same group. There are dependencies between them. Let's say I have 3 projects:
Both server and client projects depend on api.
I am trying to setup CI/CD to deploy images to GitLab registry. Based on this tutorial https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#create-maven-packages-with-gitlab-cicd I have managed to deploy version to this registry.
The problem is that if I do same on api and server, later will not download dependent api package, because ${env.CI_PROJECT_ID} will generate different id.
What is the most elegant solution, not to add multiple servers with hardcoded project ids in pom.xml.
Another question is how can I then use this repository from local environment.
Thank you all for your help.
Upvotes: 0
Views: 977
Reputation: 46
There are a few different possible solutions to this.
Publish all artifacts to one project.
You could choose one project in the group (or create a new one) and publish all artifacts into that registry. If you don't want to hardcode the Project ID you could define a CI Variable for it and use that instead of ${env.CI_PROJECT_ID}.
Publish the artifacts to multiple projects and multiple registries and add the corresponding <repository>
entries in your pom.xml
(I think you wanted to avoid this, but I thought I'd list the possibility nonetheless)
Define a custom settings.xml
instead of adding the repositories to your pom.xml
You can add it to your repository and use it with
mvn clean install -s ./settings.xml
Example with two custom CI variables:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<profiles>
<profile>
<repositories>
<repository>
<id>registry1</id>
<url>https://gitlab.com/api/v4/projects/${env.REGISTRY1}/packages/maven</url>
</repository>
<repository>
<id>registry2</id>
<url>https://gitlab.com/api/v4/projects/${env.REGISTRY2}/packages/maven</url>
</repository>
</repositories>
<id>glregistry</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>glregistry</activeProfile>
</activeProfiles>
</settings>
Another question is how can I then use this repository from local environment.
I would suggest method three for that. Add the necessary <repository>
tags to ~/.m2/settings.xml
and Maven will be able to resolve them correctly.
If the file doesn't exist yet, you can copy the example from above and simply replace the variables with the corresponding project IDs.
Upvotes: 1