How to build gitlab maven release stage using group level deploy tokens instead of deploy keys

142 views Asked by At

I am using gitlab and built a maven release stage using deploy keys at project level. Now I have created a deploy key at group level and have got username/password for that deploy token. How do I replace deploy keys with deploy token's username and password to authenticate and perform git operations?

Following script works fine, how to modify below to use deploy tokens?

release-job:
  stage: release  
  when: manual
  before_script:       
    - mkdir -p ~/.ssh/
    - cp $DEPLOY_PRIVATE_KEY ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
    - ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts
    - apt-get update && apt-get install -y git
    - git config --global user.email $GITLAB_USER_EMAIL
    - git config --global user.name $GITLAB_USER_ID
    - git checkout -B $CI_COMMIT_REF_NAME
  script:
    - mvn -Dresume=false release:prepare release:perform -s $CI_PROJECT_DIR/mvn-settings.xml

And mvn-settings.xml looks like:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Job-Token</name>
            <value>${CI_JOB_TOKEN}</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>
0

There are 0 answers