You are currently viewing .gitlab-ci.yml Part Two – Basics Of Only Except

.gitlab-ci.yml Part Two – Basics Of Only Except

.gitlab-ci.yml Part Two – Basics Of Only Except

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed the basics of jobs and pipelines in GitLab CI/CD.

https://cloudaffaire.com/gitlab-ci-yml-part-one-basics-of-script-image-services-stages/

In this blog post, we will discuss how to control the pipeline job executing with only and except.

only and except:

only and except are two parameters that set a job policy to limit when jobs are created. only defines the conditions if true, the job will run. except defines the conditions if true, the job will not run. Using only or except or both, you can control when the job will be triggered in a pipeline.

Note: The rules syntax is now the preferred method of setting job policies. only and except are candidates for deprecation, and may be removed in the future.

only and except usage:

  • only and except are inclusive. If both only and except are defined in a job specification, the ref is filtered by only and except.
  • only and except allow the use of regular expressions.
  • only and except allow to specify a repository path to filter jobs for forks.

only and except configurations:

  • branches: When a Git reference of a pipeline is a branch.
  • tags: When a Git reference of a pipeline is a tag.
  • api: When pipeline has been triggered by a second pipelines API (not triggers API).
  • external: When using CI services other than GitLab.
  • pipelines: For multi-project triggers, created using the API with CI_JOB_TOKEN.
  • pushes: Pipeline is triggered by a git push by the user.
  • schedules: For scheduled pipelines.
  • triggers: For pipelines created using a trigger token.
  • web: For pipelines created using the Run pipeline button in GitLab UI.
  • merge_requests: When a merge request is created or updated.
  • external_pull_requests: When an external pull request on GitHub is created or updated.
  • chat: For jobs created using a GitLab ChatOps command.
  • refs: The refs strategy can take the same values as all the above values.
  • kubernetes: The Kubernetes strategy accepts only the active keyword. Job is going to be created only when the Kubernetes service is active in the project
  • variables: The variables keyword is used to define variables expressions.
  • changes: Using the changes keyword with only or except makes it possible to define if a job should be created based on files modified by a Git push event.

Next, we are going to trigger some pipelies based on specific conditions to demonstarte the use cases of only and except. In the demo we have only used only for conditions for triggering the pipeline, but you can use except as well for not triggereing the pipeline.

.gitlab-ci.yml Part Two – Basics Of Only Except:

How To Trigger GitLab CI/CD Pipeline For Specific Branch:

How To Trigger The GitLab CI/CD Pipeline For Specific Tag:

How To Trigger The GitLab CI/CD Pipeline For Specific Commit Message:

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