Gitlab Webhooks

Prequisite: Please go through the steps to set up GitLab on the Production/live server before going through this tutorial.

Steps to create a staging environment using GitLab branch

1. Create a new branch for your GitLab project as shown below

1 A. Go to your project page in GitLab and click the option to add New branch

Create a Gitlab branch
Add new Gitlab branch

1 B. Create a new branch named as dev

Gitlab new branch

2. Create your staging site by copying the files and the necessary databases

3. Follow all the steps mentioned on the article Autodeployment using GitLab Webhooks on your staging sever with only the exception of Step 7 which needs to be modified slightly on the staging server. For the staging server that command would change to

Please note we are checking out only the dev branch on the staging server. So only your changes on the dev branch will be seen on this server.

4. Add the staging webhook.php file also to the list of webhooks on GitLab for Push events as shown below

GitLab Webhook

This completes setting up your staging server to preview your changes on the dev branch before they get merged to the master branch.

Now the question is how do we commit our changes?

Steps to commit your changes

    1. On your local (working) git repository first of all go on to the dev branch before you make any change
    2. Now make changes to the required files and commit your changes. Since you are on dev branch the changes will automatically get committed to the dev branch.
    3. Now push your changes to the dev server
    4. Observe the changes on the dev server
    5. Assuming the changes are ok, move on to the master branch
    6. Merge the dev branch with master
    7. Push the changes to the production/live server

Leave a Reply

Your email address will not be published. Required fields are marked *