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 [email protected] "cd /home/root/public_html/files && git pull "[email protected]:groupname/project/nas-project.git" dev && exit"
environment:
name: live
url: mywebsite.com
only:
- dev
There are two possible issues, and they both can occur at the same time.
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.
Do you have activated
ForwardAgent Yesfor 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 checkoutand 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