A gitlab-ci config to deploy to your server via ssh

  • Make sure you can connect to your server via your ssh-key without requiring password.
  • On gitlab, go to your repository > settings > CI/CD > Variables
  • Add a new variable SSH_PRIVATE_KEY. The value is your ssh private key (e.g content of ~/.ssh/id_rsa)
  • Add the file below to your project (with modifications).
  • Push

MODIFICATIONS

  • If you pay close attention to the file, you will see on LINE 17 root@example.com; you should change it to your server’s username@host.
  • Also on LINE 17, modify the cd var/… to change into your project’s root directory.
  • On LINE 15, change the URL to your website’s. This is optional though.
  • On LINE 19, it behaves like an event listener for a push to a branch. Thus, you can change it to any branch’s name. However, note that whenever an update is pushed to that branch, the auto deployment will start.
  • Make sure the branch git is pulling from on LINE 17 matches the branch name on LINE 19.

NOTE

  • This works for repositories on gitlab only.
  • Git must be installed on your server.
  • The project on your server must have been initially cloned from your repository / linked via git remote add … and in sync.

--

--

--

A programmer and web tech enthusiast! Love Angular & Laravel.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Agile processes are key to efficient software development

@projectpxn

Chad with a sword

HTTPS with nginx, using Lets Encrypt, proxying to Gogs and Jenkins back-end services

Industrial Traceability: Barcodes and 2D Codes

Ambassador Labs Open Source Update: Run Telepresence Anywhere, Community Advocates Program, and…

💥 HAVE YOU KNOWN HOW TO PLAY IN THE MINI-GAME? 💥

Kaggle Competition Training: A Student Testimonial

SFTP for Finance and Healthcare

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tofunmi Falade

Tofunmi Falade

A programmer and web tech enthusiast! Love Angular & Laravel.

More from Medium

The idea behind Docker and Linux containers

Standalone within Docker container

Running a bash script in a one-shot Ubuntu custom container on Windows

Apache Tomcat with Nginx Proxy on Ubuntu 20.04