57
loading...
This website collects cookies to deliver better user experience
$ git ls-files
.gitlab-ci.yml
README.md
backend/README.md
frontend/README.md
backend
& frontend
. Each would host files of a given part of our project. This approach scales for any number of sub-projects - we could have company-website
, slack-bot
, or whatnot inside.stages:
- build
- test
- deploy
needs:
, there is no speed penalty for adding more stages - each job is executed as soon as its requirements are defined in needs:
are met. For example, in my project, I ended up adding pre-build
to run some preparation scripts before building docker images in my project.variables:
RULES_CHANGES_PATH: "**/*"
.base-rules:
rules:
...
extends: .base-rule
- probably we could define those rules on the top level, but it's something a headache to configure everything in a way that works as expected in every case. I found it easier to have control over if the .base-rules
are set or not..base-rules:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
...
rules
are checked in order. Our 1 rule - if it's master/main, CI should always run the job.- if: '$CI_PIPELINE_SOURCE == "push"'
when: never
changes:
, we disable branch one & delay starting CI until an MR is created.- if: $CI_COMMIT_TAG
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- $RULES_CHANGES_PATH
RULES_CHANGES_PATH
variable.- when: manual
allow_failure: true
.backend:
extends: .base-rules
variables:
RULES_CHANGES_PATH: "backend/**/*"
.frontend:
extends: .base-rules
variables:
RULES_CHANGES_PATH: "frontend/**/*"
backend-build:
stage: build
extends: .backend
needs: []
script:
- echo "Compiling the backend code..."
frontend-build:
stage: build
extends: .frontend
needs: []
script:
- echo "Compiling the frontend code..."
stages:
- build
- test
- deploy
variables:
RULES_CHANGES_PATH: "**/*"
.base-rules:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: '$CI_PIPELINE_SOURCE == "push"'
when: never
- if: $CI_COMMIT_TAG
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- $RULES_CHANGES_PATH
- when: manual
allow_failure: true
.backend:
extends: .base-rules
variables:
RULES_CHANGES_PATH: "backend/**/*"
.frontend:
extends: .base-rules
variables:
RULES_CHANGES_PATH: "frontend/**/*"
backend-build:
stage: build
extends: .backend
needs: []
script:
- echo "Compiling the backend code..."
frontend-build:
stage: build
extends: .frontend
needs: []
script:
- echo "Compiling the frontend code..."
backend-test:
stage: test
extends: .backend
needs: ["backend-build"]
script:
- echo "Testing the backend code..."
frontend-test:
stage: test
extends: .frontend
needs: ["frontend-build"]
script:
- echo "Testing the frontend code..."
backend-deploy:
stage: deploy
extends: .backend
needs: ["backend-test"]
script:
- echo "Deploying the backend code..."
frontend-deploy:
stage: deploy
extends: .frontend
needs: ["frontend-test"]
script:
- echo "Deploying the frontend code..."