The OP asked about using git push, but some Maven plugins also write to the repository.
Git credentials can be cached in the git credential system or placed in
the settings.xml file.
|
git credential |
settings.xml |
git push |
X |
|
maven-release-plugin |
|
X |
versions-maven-plugin |
X |
X |
Create a (personal, project, group) access token with write-repository permission and copy it to a masked (project, group) variable REPO_TOKEN.
project/.gitlab-ci.yml:
job:
script:
- echo -e
"protocol=https\n
host=gitlab.example.com\n
username=git\n
password=$REPO_TOKEN\n"
| git credential-cache store
- git commit -m "Upload changes"
- mvn versions:use-latest-releases
- mvn release:prepare
- mvn release:perform
project/pom.xml:
<scm>
<url>https://gitlab.example.com/group/${project.artifactId}</url>
<connection>scm:git:https://gitlab.example.com/group/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://gitlab.example.com/group/${project.artifactId}.git</developerConnection>
</scm>
<properties>
<scm.tag>${env.COMMIT_ID}</scm.tag>
<project.scm.id>gitlab-scm</project.scm.id>
</properties>
~/.m2/settings.xml
<server>
<id>gitlab-scm</id>
<username>git</username>
<password>${env.REPO_TOKEN}</password>
</server>