As nobody was able to answer my question from two weeks ago, I now try to solve my problem differently.
Tldr: I need Maven to modify files in the git repository while runnigng a GitLab CI pipeline and push the changes to the repository again, all the while doing better than hacking an SSH key into my project, using a Project Access Token instead. Sadly, it looks like Maven can’t be bothered to take in the scm.connection
property on the command line.
My approach now is to read that from an environment variable:
<scm>
<!-- pom.xml stripped down to the essentials -->
<connection>{env.GITREMOTE}</connection>
</scm>
In my .gitlab-ci.yml
, I have the following bits & pieces:
before_script:
- >
echo "<settings xmlns='https://maven.apache.org/SETTINGS/1.0.0'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='https://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd'>
<servers>
# snipping unnecessary stuff
<server>
<id>snapshots</id>
<username>${NEXUS_REPO_USERNAME}</username>
<password>${NEXUS_REPO_PASSWORD}</password>
</server>
</servers>
</settings>" > settings.xml
- >
echo GIT_REMOTE=scm:git:https://$CI_PROJECT_NAME:$GIT_WRITE@$CI_SERVER_HOST/$CI_PROJECT_PATH.git > .env
GIT_WRITE
obviously is the name of the aforementioned token. The .env
file written in this step later gets sourced, but the funny thing is this: Expanding <username>${NEXUS_REPO_USERNAME}</username>
works, while the last line with scm:git:https://$CI_PROJECT_NAME:$GIT_WRITE@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
only yields scm:git:https://pipeline-test:@gitlab.com/grp/pipeline-test.git
. While I redacted the actual names, I’d like to draw your attention to the fact that the token is just missing as if the variable was not there. I can verify though that it exists:
I haven’t found anything in the documentation that helps me, so maybe anyone of you can point me to what I’m missing. Among the things I have tried are the following things:
- using brackets:
${GIT_WRITE}
- quoting with single quotes:
echo 'GIT_REMOTE=scm:git:https://$CI_PROJECT_NAME:$GIT_WRITE@$CI_SERVER_HOST/$CI_PROJECT_PATH.git' > .env
- the same with double quotes
- combinations of the above
Is my bash misbehaving? Did I get some concept of tokens wrong? I’m out of my wits here. Help greatly appreciated.