This post will show you how to set up a pipeline on Gitlab to deploy code to the server automatically whenever a merge request is made. I will try creating a pipeline deploy code to a sandbox environment to test before doing the code merge. Ok! let go…
Step 1: Install GitLab Runner
First, you need to access your server via ssh and then we install Gitlab runner using binary file. Please select the version that suitable for your server’s operating system. In my case, I choose to install on Linux x86-64.
1 | sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 |
Second, back to Gitlab and go to Settings > CI/CD and expand the Runners section. Note the URL and token because you will need it to register the runner.
1 | sudo gitlab-runner register |
Step 2: Make .gitlab-ci.yml
file
This file will be used to describe for Gitlab how to pipeline flow running. Below is an basic example file I use to deploy the code to the sandbox every time a merge request is made.
1 | stages: |
You can find more examples in here: GitLab CI/CD Examples
Step 3: Deploy with Gitlab pipeline
- Commit your file and push it to the Gitlab repo.
- Try to make a merge request and switch to CI/CD > Pipelines to view processing.