从暂存部署到生产时仅进行 运行 集成测试

Only run integration test when deploying from staging to production

我的 gitlab 项目有 3 个主要分支:devstagingproduction。我在 .gitlab-ci.yml:

中使用 postman newman 进行这样的集成测试
postman_tests:
    stage: postman_tests
    image: 
        name: postman/newman_alpine33
        entrypoint: [""] 
    only:
      - merge_requests
    script:
        - newman --version
        - newman run https://api.getpostman.com/collections/zzz?apikey=zzz  --environment https://api.getpostman.com/environments/xxx?apikey=xxxx

此脚本仅 运行 在从开发到登台或从登台到生产的合并请求批准过程中。问题是我只需要 运行 这个 postman newman 测试从暂存到生产的合并请求批准过程,我怎样才能做到这一点?

这可以使用 'advanced' only/except 设置结合提供的环境变量来实现:

postman_tests:
    stage: postman_tests
    image: 
        name: postman/newman_alpine33
        entrypoint: [""] 
    only:
      refs:
        - merge_requests
      variables:
        - $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == "staging"
        - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "production"
    script:
        - newman --version
        - newman run https://api.getpostman.com/collections/zzz?apikey=zzz  --environment https://api.getpostman.com/environments/xxx?apikey=xxxx

有关预定义环境变量的完整列表,您可以转到 here