0

I'm deploying my laravel project through CI/CD pipeline, when i trigger the deploy branch i got this error

here is my gitlab-ci.yml code

before_script:
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | ssh-add -
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

.change_file_permissions: &change_file_permissions |
  find . -type f -not -path "./vendor/*" -exec chmod 664 {} \;
  find . -type d -not -path "./vendor/*" -exec chmod 775 {} \;

deploy:
  stage: deploy
  script:
    - *change_file_permissions
    - ssh root@mywebsite.com "cd /home/root/public_html/files && git pull "git@gitlab.com:groupname/project/nas-project.git" dev && exit"
  environment:
    name: live
    url: mywebsite.com
  only:
    - dev
torek
  • 448,244
  • 59
  • 642
  • 775

1 Answers1

0

There are two possible issues, and they both can occur at the same time.

  1. Is the SSH KEY you provide within the build able to checkout the repository? aka is it either listed in your GitLab User sshkeys (not recommended) or added as a deploy key to the repository?

    If not this might be the reason that you can not check out.

  2. Do you have activated ForwardAgent Yes for your ssh config?

    SSH will not automatically forward the key you are using to connect to a server to the server itself. This means, it is maybe not available during your git checkout and therefore will not be used. see https://www.cloudsavvyit.com/25/what-is-ssh-agent-forwarding-and-how-do-you-use-it/ regarding that, and adapt your build accordingly

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36