GitLab CI: "Permission denied" when pulling in a private compose package
I am trying to set up CI with GitLab, but I am getting this build error:
[RuntimeException]
Failed to execute git clone --no-checkout 'git@***.git' '/builds/***' && cd '/builds/***' && git remote add composer 'git@***.git' && git fetch composer
Cloning into '/builds/***'...
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
My composer.json looks like this:
{
"repositories": [
{
"type": "git",
"url": "git@***.git"
}],
}
Obviously it has something to do with the ssh key pair, but I don't know where to store the private / public keys.
+3
source to share
1 answer
I just implemented a solution for this based on https://docs.gitlab.com/ee/ci/ssh_keys/README.html and an example https://gitlab.com/gitlab-examples/ssh-private-key/blob /master/.gitlab-ci.yml .
You basically need
- configure SSH agent (especially when working with docker)
- add a private SSH key (preferably from a variable stored inside GitLab since credentials don't need to be verified)
Example if the link moves:
before_script:
# install ssh-agent
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# run ssh-agent
- eval $(ssh-agent -s)
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# Set up project.
- composer install
+1
source to share