--- # 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