(set in GitLab UI → Settings → CI/CD → Variables) can be masked or protected for specific branches. 3.2 Conditional Logic with rules The only/except keywords are deprecated in favor of rules .
build: stage: build-image image: docker:20.10.16 services: - docker:20.10.16-dind script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build -t $IMAGE_TAG . - docker push $IMAGE_TAG only: - main automating devops with gitlab ci/cd pipelines read online
deploy: stage: deploy trigger: project: backend/infra branch: main strategy: depend You can trigger a pipeline via API with a token: (set in GitLab UI → Settings → CI/CD
workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never - if: $CI_COMMIT_BRANCH Now each merge request runs a full pipeline, and GitLab blocks merging if tests fail. Modern applications often consist of multiple microservices. GitLab supports cross-project automation. Triggering a downstream pipeline In project A (frontend): - docker push $IMAGE_TAG only: - main deploy: