Skip to content

Deploy from GitLab for Free

Production deploys

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.

image: plugish/php_builder:0.2a

  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo "$SSH_REMOTE" > ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts

    - docker
  script: 'rsync -vazn -e "ssh -p18765" --exclude-from exclude-list.txt --delete ./* $SSH_USER@$SSH_HOST:/'

    - docker
    - master
  when: manual
  script: 'rsync -vaz -e "ssh -p18765" --exclude-from exclude-list.txt --delete ./* $SSH_USER@$SSH_HOST:/'

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 ).

manual deploy screenshot

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


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.

Hope you have a wonderful rest of the day, and godspeed! – Jay

Pages: 1 2 3 4 5

Published inBlog

Be First to Comment

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: