Fix downstream pipeline failure on nil variable value
What does this MR do and why?
Gitlab::Ci::Variables::Collection::Item accepts a variable value that is either a String or nil, and a nil value is reachable in practice: the pipelines API marks value as optional, so triggering a pipeline with { "key": "MY_VAR", "value": null } persists it as nil.
This MR returns the value untouched when it is nil. There is nothing to expand, and forwarding nil verbatim matches what RawVariableGenerator already does for raw: true variables.
How to set up and validate locally
-
Ensure your project does not restrict pipeline variables
-
In your project use this configuration to get a parent-child-pipeline:
# --- Parent pipeline ------------------------------------------------------- trigger-downstream: stage: test rules: - if: $CI_PIPELINE_SOURCE != "parent_pipeline" trigger: include: .gitlab-ci.yml forward: pipeline_variables: true strategy: depend # --- Child pipeline -------------------------------------------------------- show-forwarded-variable: stage: test rules: - if: $CI_PIPELINE_SOURCE == "parent_pipeline" script: - echo "MY_VAR is >>>${MY_VAR}<<<" -
Trigger the parent pipeline through the API with a
null-valued variable:curl --request POST \ --header "PRIVATE-TOKEN: $TOKEN" \ --header "Content-Type: application/json" \ --data '{ "ref": "main", "variables": [{ "key": "MY_VAR", "value": null }] }' \ "https://gitlab.com/api/v4/projects/<PROJECT_ID>/pipeline" -
Before this change, the bridge fails and
Ci::CreateDownstreamPipelineWorkerraisesNoMethodError. After it, the downstream pipeline is created andMY_VARis forwarded.
References
- Resolves #603635 (closed)