The most convenient solution I figured out for my Maven projects on GitLab is using GitLab Custom environment variables of type File introduced with GitLab 11.11.
If you store the maven settings.xml
content into a GitLab environment variable e.g. named MAVEN_SETTINGS_XML
and set the type to File
, the settings will be available as file named $MAVEN_SETTINGS_XML
within each build job having access to this environment.
The maven build can pointed to this settings by either using the the param -s
(e.g mvn clean install -s $MAVEN_SETTINGS_XML
or by copying the settings to the default location via cp $MAVEN_SETTINGS_XML ~/.m2/settings.xml
before executing maven.
I'm doing the latter for now as maven sometimes struggles with the settings path.
By defining this environment variable in a GitLab Group above all maven projects, the same settings will be available to all maven projects as well.