c4ab64391d
Variables with value/description/options sub-keys, default.image in map
form, default.before_script / default.after_script as block scalars, and
rules.changes / rules.exists in {paths, compare_to} map form all caused
"yaml: cannot unmarshal !!map into string" because the struct fields were
typed too narrowly.
Changed types in model.Pipeline, model.DefaultConfig, and model.Rule to
accept any to match GitLab CI spec flexibility (13.7+ variable declarations,
15.3+ rules.changes map form, image map form in default block).
Adds testdata/script_multiline.yml covering all these patterns.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
88 lines
2.0 KiB
YAML
88 lines
2.0 KiB
YAML
---
|
|
# Exercises multi-line script patterns and extended variable declarations.
|
|
# Ref: https://docs.gitlab.com/ci/yaml/script/#split-long-commands
|
|
# Ref: https://docs.gitlab.com/ee/ci/yaml/#variablesdescription
|
|
# All patterns here must parse cleanly (exit 0).
|
|
|
|
stages:
|
|
- build
|
|
- test
|
|
- deploy
|
|
|
|
# Pipeline-level variables: plain strings and extended {value, description} map form.
|
|
variables:
|
|
PLAIN_VAR: "hello"
|
|
DEPLOY_ENV:
|
|
value: "staging"
|
|
description: "The deployment target. Set to staging or production."
|
|
RETRIES:
|
|
value: "3"
|
|
description: "Number of retry attempts."
|
|
options:
|
|
- "1"
|
|
- "3"
|
|
- "5"
|
|
|
|
default:
|
|
# image in map form (name + pull_policy)
|
|
image:
|
|
name: alpine:latest
|
|
pull_policy: if-not-present
|
|
# before_script as a block scalar (not a list)
|
|
before_script:
|
|
- apk add --no-cache curl git
|
|
|
|
build-literal-block:
|
|
stage: build
|
|
# script items using literal block scalar (|)
|
|
script:
|
|
- |
|
|
if [[ "$DEPLOY_ENV" == "production" ]]; then
|
|
echo "Production build"
|
|
else
|
|
echo "Non-production build"
|
|
fi
|
|
- echo "Build step done"
|
|
|
|
build-folded-block:
|
|
stage: build
|
|
# script items using folded block scalar (>)
|
|
script:
|
|
- >
|
|
apt-get update -qq &&
|
|
apt-get install -y curl wget
|
|
- echo "Packages installed"
|
|
before_script:
|
|
- |
|
|
echo "Job-level before_script"
|
|
echo "Using literal block scalar"
|
|
|
|
test-job:
|
|
stage: test
|
|
script:
|
|
- echo "Running tests"
|
|
- |
|
|
set -e
|
|
go test ./...
|
|
echo "Tests passed"
|
|
# Job-level variable with extended form
|
|
variables:
|
|
TEST_FLAG:
|
|
value: "true"
|
|
description: "Enable verbose test output"
|
|
# rules.changes in map form (GitLab 15.3+)
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
changes:
|
|
paths:
|
|
- "**/*.go"
|
|
compare_to: "main"
|
|
when: on_success
|
|
- when: on_success
|
|
|
|
deploy-job:
|
|
stage: deploy
|
|
script:
|
|
- echo "Deploying to $DEPLOY_ENV"
|
|
when: manual
|