【问题标题】:Only run integration test when deploying from staging to production仅在从登台部署到生产时运行集成测试
【发布时间】:2019-07-29 04:02:13
【问题描述】:

我的 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

此脚本仅在从 dev 到 staging 或 staging 到生产的合并请求批准过程中运行。问题是我只需要在从暂存到生产的合并请求批准过程中运行这个 postman newman 测试,我该如何实现?

【问题讨论】:

    标签: continuous-integration gitlab integration-testing gitlab-ci gitlab-ci-runner


    【解决方案1】:

    这可以通过结合提供的环境变量使用“高级”仅/除外设置来实现:

    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

    【讨论】:

    • 我在我的管道中得到了这个error,它说变量配置应该是键值对的哈希
    • 该错误似乎指向另一个名为“integration_tests”的作业。你复制了我上面的例子吗?
    • @secustoer 是的,我只是将我的 postman_tests 重命名为 integration_tests ,所以我只复制变量部分
    • 仅复制变量部分是不够的,不能混合使用“简单”和“高级”配置。查看添加的refs 对象。
    • 我已经重现了这个错误。 refs 块和variables 块需要有相同的缩进!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2018-11-26
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多