feat: add workflow rules to base configuration#20
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 26 minutes and 39 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdded a new Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.base.yaml:
- Around line 11-16: The branch pipeline is being created alongside the
merge_request_event pipeline causing duplicates; update the rules so the
CI_COMMIT_BRANCH branch rule is guarded by a check on $CI_OPEN_MERGE_REQUESTS
(i.e., only run the branch pipeline when there are no open merge requests for
that branch). Concretely, add a precondition before the CI_COMMIT_BRANCH rule
that checks $CI_OPEN_MERGE_REQUESTS is empty/absent, keep the existing
merge_request_event rule unchanged, and ensure the rule order places this guard
before the branch rule so pushes with open MRs skip the branch pipeline.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| - if: $CI_PIPELINE_SOURCE == "merge_request_event" | ||
| - if: $CI_PIPELINE_SOURCE == "schedule" | ||
| - if: $CI_PIPELINE_SOURCE == "pipeline" | ||
| - if: $CI_PIPELINE_SOURCE == "web" | ||
| - if: $CI_COMMIT_TAG | ||
| - if: $CI_COMMIT_BRANCH |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name ".base.yaml" -o -name "base.yaml" | head -20Repository: move-elevator/gitlab-ci-templates
Length of output: 89
🏁 Script executed:
cat -n ./.base.yamlRepository: move-elevator/gitlab-ci-templates
Length of output: 5366
🏁 Script executed:
# Check if there are more files or if jobs are defined elsewhere
wc -l ./.base.yamlRepository: move-elevator/gitlab-ci-templates
Length of output: 93
🏁 Script executed:
tail -n 109 ./.base.yaml | head -60Repository: move-elevator/gitlab-ci-templates
Length of output: 2525
🏁 Script executed:
# Check if there are any job definitions in the file with when: never clauses
grep -n "when:" ./.base.yamlRepository: move-elevator/gitlab-ci-templates
Length of output: 59
🏁 Script executed:
# Look for any job definitions in .base.yaml (they start with a name followed by colon, not indented like config items)
grep -nE "^[a-zA-Z0-9_.-]+:" ./.base.yaml | head -20Repository: move-elevator/gitlab-ci-templates
Length of output: 212
🏁 Script executed:
# Search for other files that might use .base.yaml as include
find . -name "*.yaml" -o -name "*.yml" | head -20Repository: move-elevator/gitlab-ci-templates
Length of output: 724
🏁 Script executed:
# Check one of the analyze files to see how jobs are structured and if they reference .base.yaml
head -50 ./analyze/analyze-php-cs-fixer.yamlRepository: move-elevator/gitlab-ci-templates
Length of output: 703
🏁 Script executed:
# Check if this pattern is consistent - look for job rules in other files
grep -A 10 "rules:" ./analyze/*.yaml | grep -E "(rules:|when:|merge_request_event)" | head -40Repository: move-elevator/gitlab-ci-templates
Length of output: 3400
🏁 Script executed:
# Check build jobs as well to see if the pattern is consistent
grep -A 10 "rules:" ./build/*.yaml | grep -E "(rules:|when:|merge_request_event)" | head -40Repository: move-elevator/gitlab-ci-templates
Length of output: 777
🏁 Script executed:
# Check the deploy files to see if they have different job rules
cat ./deploy/deploy-feature-cleanup-downstream.yamlRepository: move-elevator/gitlab-ci-templates
Length of output: 561
🏁 Script executed:
# Let's check a deploy job to see a simpler rule set
cat ./deploy/deploy-stage.yaml 2>/dev/null || cat ./deploy/deploy-*.yaml | head -60Repository: move-elevator/gitlab-ci-templates
Length of output: 668
🏁 Script executed:
# Let's check the git history to understand the context of this change
git log --oneline -20 2>/dev/null || echo "Git history not available"Repository: move-elevator/gitlab-ci-templates
Length of output: 131
🌐 Web query:
GitLab CI $CI_OPEN_MERGE_REQUESTS variable workflow rules
💡 Result:
The $CI_OPEN_MERGE_REQUESTS predefined variable in GitLab CI/CD is a comma-separated list of up to four open merge request IIDs (e.g., "gitlab-org/gitlab!333,gitlab-org/gitlab-foss!11") for the current branch and project as the source. It is available in pre-pipeline phase for branch pipelines and merge request pipelines when the branch has associated open merge requests (introduced in GitLab 13.8). It is commonly used in workflow:rules to prevent duplicate pipelines when both branch and merge request pipelines would trigger on a push to a branch with open MRs. Example configuration: workflow: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS when: never - if: $CI_COMMIT_BRANCH This runs: - Merge request pipelines for merge_request_event. - Skips branch pipelines (push) if open MRs exist for the branch. - Runs branch pipelines only if no open MRs. The variable is set only if open MRs exist; otherwise, it is unset (if: $CI_OPEN_MERGE_REQUESTS evaluates false).
Citations:
- 1: https://docs.gitlab.com/ci/variables/predefined_variables/
- 2: https://docs.gitlab.com/16.11/ee/ci/variables/predefined_variables.html
- 3: https://docs.gitlab.com/ee/ci/yaml/workflow.html
- 4: https://docs.gitlab.com/17.2/ee/ci/yaml/workflow.html
- 5: https://docs.gitlab.com/ci/yaml/workflow/
🏁 Script executed:
# Check if there are any jobs that actually allow merge_request_event, schedule, or pipeline sources
# by looking for jobs that either don't have rules or have different rules
find . -name "*.yaml" -o -name "*.yml" | xargs grep -L "when: never" | xargs grep -l "merge_request_event\|CI_PIPELINE_SOURCE" 2>/dev/null | head -10Repository: move-elevator/gitlab-ci-templates
Length of output: 89
Duplicate pipelines will be created for branches with open merge requests.
When you push to a branch with an open MR, the current workflow rules (lines 11 and 16) trigger two separate pipelines: one for merge_request_event and one for CI_COMMIT_BRANCH. The first pipeline runs with no jobs since all jobs explicitly block merge_request_event source with when: never, creating an empty/wasted pipeline.
To prevent this, add a guard before the branch rule using $CI_OPEN_MERGE_REQUESTS:
🔧 Proposed fix
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "pipeline"
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_COMMIT_TAG
+ - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
+ when: never
- if: $CI_COMMIT_BRANCHThis skips the branch pipeline when an MR is already open for that branch, eliminating the duplicate pipeline.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - if: $CI_PIPELINE_SOURCE == "merge_request_event" | |
| - if: $CI_PIPELINE_SOURCE == "schedule" | |
| - if: $CI_PIPELINE_SOURCE == "pipeline" | |
| - if: $CI_PIPELINE_SOURCE == "web" | |
| - if: $CI_COMMIT_TAG | |
| - if: $CI_COMMIT_BRANCH | |
| - if: $CI_PIPELINE_SOURCE == "merge_request_event" | |
| - if: $CI_PIPELINE_SOURCE == "schedule" | |
| - if: $CI_PIPELINE_SOURCE == "pipeline" | |
| - if: $CI_PIPELINE_SOURCE == "web" | |
| - if: $CI_COMMIT_TAG | |
| - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS | |
| when: never | |
| - if: $CI_COMMIT_BRANCH |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.base.yaml around lines 11 - 16, The branch pipeline is being created
alongside the merge_request_event pipeline causing duplicates; update the rules
so the CI_COMMIT_BRANCH branch rule is guarded by a check on
$CI_OPEN_MERGE_REQUESTS (i.e., only run the branch pipeline when there are no
open merge requests for that branch). Concretely, add a precondition before the
CI_COMMIT_BRANCH rule that checks $CI_OPEN_MERGE_REQUESTS is empty/absent, keep
the existing merge_request_event rule unchanged, and ensure the rule order
places this guard before the branch rule so pushes with open MRs skip the branch
pipeline.
Summary
workflow:rulesblock to.base.yamlto control when pipelines are createdChanges
.base.yaml— newworkflow:rulessection defining pipeline creation conditionsSummary by CodeRabbit