Create Automatic Deploy with GitLab CI

Alfredo Barron
modulr
Published in
2 min readJun 11, 2020

--

Create automatic deploy with GitLab CI in 10 minutes

Step 1. Add public key on GitLab profile

Add the server’s public key to the GitLab profile's public keys. This is done by copying in the contents of cat ~/.ssh/id_rsa.pub and pasting them to https://gitlab.com/profile/keys

Step 2. Add public key to authorized keys

Add the server’s public key to the server’s authorized keys. Inside the server, this is done by simply running this line:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Step 3. Add private key on GitLab project

Add the server’s private key to the Gitlab project variables. This is done by copying in the contents of cat ~/.ssh/id_rsa and pasting them to https://gitlab.com/username/project/-/settings/ci_cd with name SSH_PRIVATE_KEY

Step 4. Create .gitlab-ci-yml file

Create .gitlab-ci.yml file into root project and put bellow code:

before_script:  ## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
##
- 'which ssh-agent || (…

--

--