Hello everyone. I was wondering if anyone could provide some input on what I could do to improve my CI/CD Pipeline. I am needing to do both merge request and branch pipelines.
#Global Rules for all jobs unless otherwise specified
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
#For Merge Requests into the main branch
dev_build:
stage: build
image: alpine
script:
- echo "Building ..."
- echo "Small change!"
dev_test:
stage: test
image: alpine
needs:
- dev_build
script:
- echo "Testing ..."
dev_deploy:
stage: deploy
image: alpine
needs:
- dev_test
script:
- echo "Deploying"
#For changes merged into main branch
int_build:
stage: build
image: alpine
rules:
- if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
script:
- echo "Building changes + existing code"
int_test:
stage: test
image: alpine
needs:
- int_build
rules:
- if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
script:
- echo "testing integration"
int_deploy:
stage: deploy
image: alpine
rules:
- if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
needs:
- int_test
script:
- echo "Deploying integration"
#For merge requests into the master branch
master_dev_build:
stage: build
image: alpine
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
script:
- echo "Building ..."
- echo "Small change!"
master_dev_test:
stage: test
image: alpine
needs:
- master_dev_build
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
script:
- echo "testing integration"
master_dev_deploy:
stage: deploy
image: alpine
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
needs:
- master_dev_test
script:
- echo "Deploying integration"
#For changes merged into the master branch
master_build1:
stage: build
image: alpine
rules:
- if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'
script:
- echo "Building ..."
- echo "Small change!"
master_test1:
stage: test
image: alpine
needs:
- master_build1
rules:
- if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'
script:
- echo "testing integration"
master_deploy1:
stage: deploy
image: alpine
rules:
- if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'
needs:
- master_test1
script:
- echo "Deploying integration"
Both dev_build ones are for merge request. The default branch is develop so we have a merge request build and deploy once it goes there and then another one when it goes into master. This is santized code for what we are using.