1

I am trying to create a job inside .gitlab-ci.yml which will create a new branch based on my current branch. The yml that I created is

  - release
  

start:
  stage: release
  before_script:
    - git config --global user.name "${GITLAB_USER_NAME}"
    - git config --global user.email "${GITLAB_USER_EMAIL}"

  script:
    - git checkout -b release
    - git branch -a
    - git remote -v
    - git push --set-upstream origin release 

at the point of pushing it upstream I get the following error. It is weird that in the error the link of the origin has an extra ' at the end. I am not sure if this bug doesn't have any significance or is it trying to reach the wrong url with this ' at the end.

I believe create a new branch from the pipeline should be possible. Any ideas what I could be missing? enter image description here

adi1992
  • 75
  • 11
  • 1
    The error returned is 403, which stands for `Forbidden`. It means that authentication succedeed, but your gitlab-ci-token does not have the rights to push to the repository. Try to create a token with write access to the repository. – Davide Calarco Aug 11 '22 at 09:16
  • @DavideCalarco Thanks for your quick reply. I have already created a token with write access, which I am using to push to the remote from my local computer through command line. However to do it from the pipeline, how should I include the token information there? – adi1992 Aug 11 '22 at 09:32
  • 1
    Define a variable in GitLab GUI: go in Settings -> CI/CD -> Variables -> Expand -> Add variable. Name it as you want, for instance `PUSH_TOKEN`, and paste there the value of the token; check that the `Mask variable` flag is set to true. Then, reference the variable in your job through ${PUSH_TOKEN}. In your case, gitlab-ci-token:${PUSH_TOKEN}@gitlab.com – Davide Calarco Aug 11 '22 at 09:47
  • @DavideCalarco Thanks. I followed your suggestion. Now I run into the following error `remote: HTTP Basic: Access denied fatal: Authentication failed for 'https://gitlab-ci-token:@gitlab.com/aditya.sondhi1992/my_devops/'` – adi1992 Aug 11 '22 at 10:13
  • 1
    It seems that the job did not replaced correctly the token value. Indeed, in your log the part between the colon `:` and the rate `@` is empty. Check that the variable name specified in the job source matches the name of the variable you set in GitLab GUI settings, in my example PUSH_TOKEN. Additionally, open again the CI/CD settings of the variable and check that the `Protect variable` flag is unset. – Davide Calarco Aug 11 '22 at 10:51
  • @DavideCalarco Thanks a lot. Unsetting the Protect variable actually solved the issue. – adi1992 Aug 11 '22 at 11:17
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/247200/discussion-between-davide-calarco-and-adi1992). – Davide Calarco Aug 11 '22 at 12:06

0 Answers0