mueckehro
mueckehro

Reputation: 11

How can I connect maven-scm-plugin with GitLab Ci via HTTPS?

We build our project with maven and use GitLab Ci to deploy it into our nexus repository. The live deployment is done by another team which requested to receive the "scmCommitId" to check, if the correct version is deployed. Therefor we must establish scm connection.

I tried to use scm-connection in pom.xml file like:

<scm>
  <connection>scm:git:https://gitlab-ci-token:[email protected]:path/to/project/projectname.git</connection>
</scm>

If i use scm:git:[email protected]:path/to/project/projectname.git locally it works and maven build connects and shows the last commits like:

| master-SNAPSHOT
|\
||                                                                        by [Developer]
||                                                                        [86d70a0]
||                                                                        by [Developer]
||                                                                        [2122a35]
||                                                                        by [Developer]
||                                                                        [790f523]
|| ...

If i use the same code on GitLab Ci it can not connect, because GitLab Ci requests connection via HTTPs. So I did try to use:

scm:git:https://gitlab-ci-token:[email protected]:path/to/project/projectname.git by replacing GITLAB-CI-TOKEN in my gitlab-ci.yml in before_script by $CI_JOB_TOKEN:

  before_script:
    - sed -i "s/GITLAB-CI-TOKEN/$CI_JOB_TOKEN/g" pom.xml
  script: mvn package 
  after_script:
    - sed -i "s/$CI_JOB_TOKEN/GITLAB-CI-TOKEN/g" pom.xml

This is still not working:

something is wrong with your scm connection: "://gitlab-ci-token:TOKENgitlabserver.com:path/to/project/projectname.git" != "https://gitlab-ci-token:TOKENgitlabserver.com:path/to/project/projectname.git"
raw: "scm:git:https://gitlab-ci-token:[MASKED]@gitlabserver.com:path/to/project/projectname.git" != "https://gitlab-ci-token:[MASKED]@gitlabserver.com:path/to/project/projectname.git"

Somewhere the "https" protocol gets lost. If I try http instead, it will keep the protocol but fail because it is the wrong protocol:

something is wrong with your scm connection: "http://gitlab-ci-token:TOKENgitlabserver.com:path/to/project/projectname.git" != "https://gitlab-ci-token:TOKENgitlabserver.com:path/to/project/projectname.git"

Is it possible to connect via https? Or is it possible to tell GitLab Ci to request another method like maybe connect via ssh? Or maybe just to test, if it would be working, to tell GitLab to use http instead?

Upvotes: 1

Views: 734

Answers (0)

Related Questions