Deploy from GitLab for Free

So, we’ve set up a deploy test to make sure we can actually deploy to the server, now let’s fire this puppy off. It’s actually easier than you might think, but we want to make sure deploys are manual, and that prod deploys only fire from the branch we want.

Boom done, notice the new stage_deploy job? You’ll see it has a few things added and one removed, can you spot the removal? Yep, we removed the -n flag from the rsync command, so this is no longer a dry-run.

I desperately suggest you test this in another folder other than wp-content on first deploy to make sure you don’t break anything. Testing on a staging server with a backup is really great and you’d get bonus points from me!

We’ve also added the ‘only’ setting to make sure this job only runs on the branch specified. More info on only. Basically, we only deploy when a push is made to master.

The ‘when’ setting makes sure the deploy is not automatic, if you prefer otherwise, omit this setting. This means you will have to go to the jobs section ( previously shown ) and click the deploy button manually if the job succeeds.

Finishing up

Now you’ve added the production job to the config you’ll need to commit it as you normally would when you push, you’ll be greeted with a new play button ( or run button if you want to call it that ).

Simply click that lovely little button and you’re off to the races!

Conclusion

Wow, you’ve made it this far I’m absolutely humbled. Honestly, this is the longest article I’ve written in about a year. I wanted to write this with newbie’s in mind, so yes, there was a ton of information that you may have known, but as a dev, I hate it when people don’t explain things in detail. Maybe I’m weird, but I’m okay with that.

GitLab is super powerful, and no I wasn’t joking about starting the dishwasher with a commit. It’s doable, you just have to cross boundaries. Think outside the box.

If this article proved to be helpful to you please do share it! I love spreading my knowledge and learning from others. If you have areas for improvement please leave a comment, after all I can’t get better at writing unless I know where I’m screwing up.