Moving from only syntax to rules syntax in GitLab CI/CD v13.x+

Josh Sherman
2 min read
Software Development DevOps

Saw a recent announcement from GitLab that the only and except syntax for GitLab CI/CD was going to be deprecated soon in the v13 release.

Amendment: The only / except syntax isn’t actually being deprecated as pointed out by Jason Yavorska. It’s actually related to a template that is deprecating said syntax.

That one’s on me as I couldn’t find the original notification about this to verify. I still ported my stuff over and plan to continue to use the rules syntax moving forward as it seems to provide a ton more flexibility that I may end up utilizing in the future.</em>

Not wanting to be stuck wondering why my builds are erroring out once that release drops, I figured I should put some time this week to shore up my projects that are using GitLab CI/CD and make sure I’m on the latest and greatest syntax.

Unfortunately, the latest and greatest syntax is also a bit more complex and I was left sifting through the docs a bit more than I would have liked, considering I would assume that a deprecation of this magnitude would have justified a bit of a migration guide with before and after syntax to be able to copy pasta.

Fortunately, at least for my use case, it didn’t take much to port the syntax over. Keep in mind, my usage is extremely simplistic so your mileage may vary if you’re looking for some robust guide to every possible scenario.

For me, simply limiting my deploy stage to only run on master is more than sufficient. The syntax looks something like this (truncated of course):

deploy:
  stage: deploy
  only:
    - master

The new syntax is a bit more verbose, but still only 2 lines:

deploy:
  stage: deploy
  rules:
    - if: $CI_COMMIT_BRANCH == "master"

Not a whole lot to it, but as mentioned, I didn’t think their documentation did a good job with this one, so seemed worth documenting. Especially if I happen to forget one of my repos and have to remember what the hell I did to get things working again!

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Engineering Manager and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles