1

如何在我的.gitlab-ci.yml?

我想将它插入该after_script部分,以便我可以使用工件的链接进行 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"'
4

1 回答 1

1

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

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

于 2022-02-24T16:02:31.710 回答