Home > Enterprise >  Git Push command fails in git lab pipeline
Git Push command fails in git lab pipeline

Time:07-14

I have created a pipeline to tag and push the commit, I am getting access denied when I push the code to remote origin from the gitlab job.

Note: The script is working fine in the local machine.

 - Pushing release to origin
remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab-ci-token:[MASKED]@xxxxx/xxxx/test_repo.git/': The requested URL returned error: 403
origin
- Switching back to HEAD branch. (restoring local changes)

.gitlab-ci.yml

build:
  stage: build
  before_script:
    - git config --global user.email "${CI_EMAIL}" && git config --global user.name "${CI_USERNAME}"
  script:
    - bash ./tag-release.sh -b main -t $release 

CodePudding user response:

You cannot use the builtin CI token to push to the repo. Instead, you'll need an API token with appropriate scope to push to the repo. A good way to do this is to use project access tokens. Once you have to token, you can put it in the project CICD variables settings. Then use that API token variable instead of CI_JOB_TOKEN.

CodePudding user response:

I have removed the existing origin settings using git remote rm origin

then added the remote origin with the project access tokens.

git remote add origin https://<access-token-name>:<access-token>@gitlab.com/username/reponame.git 

added the personal access token(GIT_TOKEN_VALUE) and personal access token name(GIT_TOKEN_NAME) in cicd variables and masked/protected it for security purpose.

git remote add command with cicd variable is git remote add origin https://${GIT_TOKEN_NAME}:${GIT_TOKEN_VALUE}@gitlab.com/username/reponame.git

  • Related