GITLAB CI/CD:如何知道一个流水线是标签流水线、MR流水线还是调度流水线?

GITLAB CI/CD: How to know if a pipeline is a tag pipeline, an MR pipeline or a scheduled pipeline?

只有当它是标记管道时,我才想 运行 脚本的一部分。我如何将其表示为条件?

您可以使用规则或唯一关键字 运行 仅在标签或合并请求上。

规则:

job1:
  script:
    - echo "This job runs in merge request pipelines"
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

仅:

job1:
  script:
    - echo "This job runs in merge request pipelines"
  only:
    - merge_requests

至 运行 仅在您可以使用的标签上:

job1:
  script:
    - echo "This job runs only on tags"
  only:
    - tags

文档:https://docs.gitlab.com/ee/ci/yaml/#onlyrefs--exceptrefs