.gitlab-ci.yml Part Three – Basics Of Rules

.gitlab-ci.yml Part Three – Basics Of Rules

.gitlab-ci.yml Part Three – Basics Of Rules

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to control the pipeline job executing with only and except.

https://cloudaffaire.com/gitlab-ci-yml-part-two-basics-of-only-except/

In this blog post, we will discuss how to perform the same with new GitLab feature rules.

Rules:

Rules allow for a list of individual rule objects to be evaluated in order, until one matches and dynamically provides attributes to the job. Note that rules cannot be used in combination with only/except since it is intended to replace that functionality. If you attempt to do this the linter will return a key may not be used with rules error.

Available rule clauses include:

  • if (similar to only:variables)
  • changes (same as only:changes)
  • exists

.gitlab-ci.yml Part Two – Job Conditions Using Only And Except

rules – if:

rules:if differs slightly from only:variables by accepting only a single expression string, rather than an array of them. Any set of expressions to be evaluated should be conjoined into a single expression using && or ||, and use the variable matching syntax. If none of the provided rules match, the job will be set to when:never, and not included in the pipeline. If rules:when is not included in the configuration at all, the behavior defaults to job:when, which continues to default to on_success.

rules – changes:

rules: changes work exactly the same way as only: changes and except: changes, accepting an array of paths. Similarly, it will always return true if there is no Git push event.

rules – exist:

exists accepts an array of paths and will match if any of these paths exist as files in the repository. You can also use glob patterns to match multiple files in any directory within the repository.

Hope you enjoyed this article. In the next blog post, we will continue our discussion .gitlab-ci.yml.

To get more details on GitLab you can follow the below link.

https://docs.gitlab.com/ee/README.html

To Get more details on Git you can follow the below links.

https://cloudaffaire.com/category/devops/git/

https://git-scm.com/doc

 

Leave a Reply

Close Menu