Reputation: 45
I need the VM created by the gitlab-ci.yml (running Ubuntu 14.04) to install packer and then both access and download either my entire private gitlab repo, or just an individual file from that repo.
First I tried creating an ssh key in my script that creates the container and vm, and then remotely adding the .pub to the gitlab repo. However I forgot that the newly created container is discarded upon completion of the build. Meaning new keys are generated every time the container is created.
Is there anyway that I can dynamically add and delete keys to a private GitLab repo?
Upvotes: 0
Views: 1757
Reputation: 137398
To use SSH keys in a GitLab CI Docker container to access other repositories on the GitLab server:
SSH_PRIVATE_KEY
before_script
in your .gitlab-ci.yml
fileGITLAB_HOST_KEY
before_script
in your .gitlab-ci.yml
filebefore_script:
# Add SSH private key and GitLab server host key
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p /root/.ssh
- echo "$GITLAB_HOST_KEY" >> /root/.ssh/known_hosts
Upvotes: 5