Explain how to quote a joined rules:if expression
What does this MR do?
When a rules:if joins expressions with && or || and is put in quotes, the quotes have to wrap the whole expression. The issue shows what happens when they wrap only a later part:
- if: $CI_PIPELINE_SOURCE == "schedule" && '"$[[ inputs.run_interval ]]" == "weekly"'YAML keeps those single quotes, so the quoted part is a string in the expression rather than a comparison, and a non-empty string is true: the job is added to every scheduled pipeline, whatever the input is.
As suggested in review, this MR adds two sentences and a one-line example at the end of Join variable expressions together, in doc/ci/jobs/job_rules.md, and leaves the CI/CD inputs examples page as it is on master.
How I checked it
A scratch spec, not part of this MR, run in a local GitLab test environment on this branch (one docs commit on b00391b1ec3). It creates pipelines with Ci::CreatePipelineService from this configuration, with <rule> replaced by each form below and the two variables set as listed:
variables:
VARIABLE1: "<value>"
VARIABLE2: "<value>"
build-job:
script: echo "always runs"
check-job:
script: echo "runs when the rule is true"
rules:
- if: <rule>whole quoted: '$VARIABLE1 =~ /^content.*/ && $VARIABLE2 == "something"'
later part quoted: $VARIABLE1 =~ /^content.*/ && '$VARIABLE2 == "something"'
later part quoted (||): $VARIABLE1 =~ /^content.*/ || '$VARIABLE2 == "something"'
later part, same quotes: $VARIABLE1 =~ /^content.*/ && "$VARIABLE2 == "something""
first part quoted: '$VARIABLE1 =~ /^content.*/' && $VARIABLE2 == "something"
first part quoted (||): '$VARIABLE1 =~ /^content.*/' || $VARIABLE2 == "something"
whole quoted, VARIABLE2=something jobs=["build-job", "check-job"]
whole quoted, VARIABLE2=other jobs=["build-job"]
later part quoted, VARIABLE2=other jobs=["build-job", "check-job"]
later part quoted, VARIABLE1=other-1 jobs=["build-job"]
later part quoted (||), both other jobs=["build-job", "check-job"]
later part, same quotes error=jobs:check-job:rules:rule if invalid expression syntax
first part quoted error=(): did not find expected alphabetic or numeric character while scanning an anchor at line 9 column 40
first part quoted (||) error=(): did not find expected comment or line break while scanning a block scalar at line 9 column 40With the whole expression quoted, the job is added only when both comparisons are true. With a later part quoted, that part is the string $VARIABLE2 == "something", which is always true, so only the unquoted part decides, and with || the job is always added. If that part contains the quote character that wraps it, the expression is invalid. With the first part quoted, YAML refuses the line. In the last two cases, pipeline creation fails with the error shown.
The same spec creates pipelines from the CI/CD inputs example as the page has it (the job is added only when the input is test-branch) and with its single quotes removed, which is not valid YAML: see the thread on that line.
Lint
scripts/lint-doc.shon the page, in the lint image thedocs-lint markdownjob uses (markdownlint-cli2 0.23.2, Vale 3.21.0): passed, with no markdownlint issues.- Vale at suggestion level on this branch and on master: the only finding on either is
gitlab_base.ReadingLevelfor the page, 7.15 on this branch and 7.17 on master. lychee --offline --no-progress --include-fragmentson the page, as thedocs-lint linksjob runs it: 0 errors.- The commit message passes
scripts/lint/commit_linter.rband the Danger commit linter (gitlab-dangerfiles 4.12.0).
Related issues
Closes #628757 (closed)
Author's checklist
- Optional. Consider taking the GitLab Technical Writing Fundamentals course.
- Follow the:
- If you're adding a new page, add the product availability details under the H1 topic title.
- If you are a GitLab team member, request a review based on:
- The documentation page's metadata.
- The associated Technical Writer.
If you are a GitLab team member and only adding documentation, do not add any of the following labels:
~"frontend"~"backend"~"type::bug"~"database"
These labels cause the MR to be added to code verification QA issues.
Reviewer's checklist
Documentation-related MRs should be reviewed by a Technical Writer for a non-blocking review, based on Documentation Guidelines and the Style Guide.
If you aren't sure which tech writer to ask, use roulette or ask in the #docs Slack channel.
- If the content requires it, ensure the information is reviewed by a subject matter expert.
- Technical writer review items:
- Ensure docs metadata is present and up-to-date.
- Ensure the appropriate labels are added to this MR.
- Ensure a release milestone is set.
- If relevant to this MR, ensure content topic type principles are in use, including:
- The headings should be something you'd do a Google search for. Instead of
Default behavior, say something likeDefault behavior when you close an issue. - The headings (other than the page title) should be active. Instead of
Configuring GDK, say something likeConfigure GDK. - Any task steps should be written as a numbered list.
- If the content still needs to be edited for topic types, you can create a follow-up issue with the docs-technical-debt label.
- The headings should be something you'd do a Google search for. Instead of
- Review by assigned maintainer, who can always request/require the reviews above. Maintainer's review can occur before or after a technical writer review.