Skip to content

Surface error when needed job name exceeds length limit in CI pipeline

Leaminn Ma requested to merge detect-needs-job-name-limit-exceeded into master

What does this MR do and why?

Background context:

Given a parallel job defined like so:

base_job_name:
  script: echo
  parallel: 1

its job name will be expanded to base_job_name 1/1.

Given a parallel job with matrix defined:

base_job_name:
  script: echo
  parallel:
    matrix:
      - VAR1: a

its job name will be expanded to base_job_name: [a]. If multiple variables are defined ({VAR1: a, VAR2: b}), the name will be expanded to base_job_name: [a, b].

Problem:

Currently, no validation error appears when a job needs a parallel job whose expanded name exceeds the limit of 128 characters. Instead, the pipeline fails to be created without any error message as described in #362262 (closed).

Fix:

This MR surfaces this validation error. Additional notes:

  • The limit is already documented (under "Additional details:").
  • While this validation check is not specific to parallel jobs, it will be the most common case for this error since the expanded names of parallel jobs aren't visible in the pipeline editor.
  • Adding a validation in the Entry::Need class is not sufficient for a couple reasons:
    • The length limit is intended to be increased to match the job name length limit (255 characters) in Step 2 of #362262 (closed). Since you can't need a non-existent job name, this length limit will already be covered by the job entry validation.
    • Entry class validations happen before a parallel job's name is fully expanded in Ci::Config::Normalizer.

Resolves Step 1 of #362262 (closed)

Screenshots or screen recordings

Validation error is now detected. Examples:

Example 1: Needing a non-parallel job whose name is too long.

129-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii:
  script: echo

child-job:
  script: echo
  needs:
    - 129-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Before After
Screenshot_2023-08-15_at_9.52.54_AM Screenshot_2023-08-15_at_10.22.52_AM
Screenshot_2023-08-15_at_9.54.14_AM Screenshot_2023-08-15_at_10.24.06_AM

Example 2: Needing a parallel job whose base name is too long.

125-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii:
  script: echo
  parallel: 2

child-job:
  script: echo
  needs:
    - 125-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Before After
Screenshot_2023-08-15_at_9.58.41_AM Screenshot_2023-08-15_at_10.26.44_AM
Screenshot_2023-08-15_at_9.54.14_AM Screenshot_2023-08-15_at_10.27.41_AM

Example 3: Needing a parallel job whose single matrix value is too long.

parent-job:
  script: echo
  parallel:
    matrix:
      - VAR1: 115-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

child-job:
  script: echo
  needs:
    - parent-job
Before After
Screenshot_2023-08-15_at_10.05.24_AM Screenshot_2023-08-15_at_10.28.48_AM
Screenshot_2023-08-15_at_9.54.14_AM Screenshot_2023-08-15_at_10.29.51_AM

Example 4: Needing a parallel job whose multiple matrix values are too long.

parent-job:
  script: echo
  parallel:
    matrix:
      - VAR1: 60-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
        VAR2: 53-chars_iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

child-job:
  script: echo
  needs:
    - parent-job
Before After
Screenshot_2023-08-15_at_10.17.58_AM Screenshot_2023-08-15_at_10.30.15_AM
Screenshot_2023-08-15_at_9.54.14_AM Screenshot_2023-08-15_at_10.30.51_AM

How to set up and validate locally

For each of the examples in the above section:

  1. In your project's pipeline editor, update your .gitlab-ci.yml file with the example content.
  2. Observe that the validation error is caught in the pipeline editor as well as when running the pipeline.
  3. (Optional) Observe that if you reduce the long name or variable value by 1 character, there are no validation errors and the pipeline runs successfully.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #362262 (closed)

Edited by Leaminn Ma

Merge request reports