Fail pipeline creation when pipeline variables are too large

What does this MR do and why?

Pipeline variables are stored as a pipeline_variables pipeline artifact. The artifact is built through the pipeline_artifacts_pipeline_variables has_one association, which does not validate on save. When the variables JSON is larger than Ci::PipelineArtifact::FILE_SIZE_LIMIT (10 MiB), the artifact fails its size validation, Rails skips saving it without raising, and pipeline.save! still succeeds. The pipeline runs without its variables and the user sees no error.

This MR checks the JSON size in PipelineVariablesArtifactBuilder before building the artifact. If it is over the limit, pipeline creation fails with a config_error, the same way invalid variables are handled in Chain::Build::Associations:

Failed to build pipeline variables: total size exceeds the limit of 10 MiB

The check is behind the ci_enforce_pipeline_variables_total_size_limit beta feature flag, disabled by default. When the flag is disabled, the previous behavior is kept.

References

Screenshots or screen recordings

Before:

Screenshot_2026-10-13_at_14.06.12

After:

Screenshot_2026-10-13_at_14.06.21

How to set up and validate locally

  1. Use any project with a .gitlab-ci.yml that has at least one job on the default branch, for example:

    test:
      script: echo $BIG | wc -c
  2. Open a Rails console:

    gdk rails console
  3. Enable the feature flag:

    Feature.enable(:ci_enforce_pipeline_variables_total_size_limit)
  4. Create a pipeline with a single pipeline variable just over 10 MiB:

    project = Project.find_by_full_path('<your-project-path>')
    user = User.find_by_username('root')
    value = 'a' * (Ci::PipelineArtifact::FILE_SIZE_LIMIT + 1.kilobyte)
    
    pipeline = Ci::CreatePipelineService
      .new(project, user, ref: project.default_branch, variables_attributes: [{ key: 'BIG', value: value }])
      .execute(:web)
      .payload
  5. Inspect the result:

    pipeline.created_successfully?
    pipeline.status
    pipeline.failure_reason
    pipeline.error_messages.map(&:content)
    Ci::PipelineArtifact.where(pipeline_id: pipeline.id, file_type: :pipeline_variables).exists?
    Ci::Pipeline.find(pipeline.id).variables.to_a
    pipeline.builds.map(&:name)
  6. Compare with the expected output:

    master This MR
    created_successfully? true false
    status "created" "failed"
    failure_reason nil "config_error"
    error_messages [] ["Failed to build pipeline variables: total size exceeds the limit of 10 MiB"]
    variables artifact exists? false false
    variables [] (silently dropped) []
    builds ["test"] (runs without BIG) []
  7. Optional: run the same steps with a small value (for example 'a' * 100) and check the pipeline is created and Ci::Pipeline.find(pipeline.id).variables returns BIG.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Furkan Ayhan

Merge request reports

Loading
Loading