For example - we want that the job should be executed only on master branch when a merge occur.
We need a condition what will check if we are in the master branch. This can be done using rules.
Use rules to include or exclude jobs in pipelines.
Example:
deploy to s3:
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- aws --version
- aws s3 sync build s3://$AWS_S3_BUCKET --delete
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
Where:
CI_COMMIT_REF_NAME - The branch or tag name for which project is built