如何在yaml中的折叠字符串中插入变量?

How to insert a variable in a folded string in yaml?

如何在 .gitlab-ci.yml 中插入变量?

我想将它插入 after_script 部分,这样我就可以使用将使用此管道生成的工件的 link 进行 Webhook 调用。

我尝试了以下方法,但它只是将其读取为字符串。

stages:
- build

flutter_build_android:
  timeout: 1h
  stage: build
  before_script:
    - flutter clean
    - flutter pub get
  script:
    - flutter build apk --dart-define=SDK_REGISTRY_TOKEN="${MAPBOX_TOKEN}"
    - cp build/app/outputs/apk/release/app-release.apk ./
  artifacts:
    paths:
      - ./app-release.apk
    when: on_success
    expire_in: 30 days
  after_script:
    - >
      curl -H 'Content-Type: application/json' -d '{"text": "http://gitlab.company.pl/mobile/flutter/myproject/-/jobs/artifacts/$CI_JOB_ID/download?job=$CI_JOB_NAME"}' https://link.to.my/webhook/eca8
  tags:
    - gradle
    - flutter
  rules:
    - if: '$CI_COMMIT_BRANCH == "rc"'

Bash 不会展开单引号内的变量。您可以在变量前结束单引号并在之后继续:

    - >
      curl -H 'Content-Type: application/json'
      -d '{"text": "http://gitlab.company.pl/mobile/flutter/myproject/-/jobs/artifacts/'"$CI_JOB_ID"'/download?job='"$CI_JOB_NAME"'"}'
      https://link.to.my/webhook/eca8

(我将变量放在双引号中,在这种情况下这不是必需的,但通常是很好的做法。)