My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Gitlab Pipeline to Clone from Private Github repo

Emil Moe's photo
Emil Moe
·Sep 13, 2019

I want to clone some private repositories from Github when I run my pipelines on Gitlab on my project. The main project is hosted on Gitlab.

This is my gitlab.yml part where I try to add the key:

    - eval $(ssh-agent -s)
      - echo "$GITHUB_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
      - ssh-keyscan github.org >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts

I have stored the $GITHUB_PRIVATE_KEY as a variable. It is a private SSH key and inserted to Gitlab as a key string - single line.

The snippet above is executed during "script".