【问题标题】:How do I write pre-deployment scripts to run newman postman test in .gitlab-ci.yml file如何编写预部署脚本以在 .gitlab-ci.yml 文件中运行 newman postman 测试
【发布时间】:2019-09-06 11:58:30
【问题描述】:

我想在 gitlab-ci.yml 中使用 newman 设置部署前邮递员测试,如果测试通过则部署如果测试失败则部署将被取消。

这是我的 .gitlab-ci.yml 文件 -

variables:
        POSTMAN_COLLECTION : collection.json
    POSTMAN_ENVIRONMENT: postman-test.postman_environment.json

stages:
    - build
    - test

build:
    stage: build

    script:
      - docker build -t registry.tech5-sa.com/t5-platform/t5-templates-db_app:$CI_COMMIT_REF_NAME --build-arg UID=$(id -u) -f API/Dockerfile .
      - docker build -t registry.tech5-sa.com/t5-platform/t5-templates-db_postgresql:$CI_COMMIT_REF_NAME --build-arg UID=$(id -u) -f API/Dockerfile.postgresql .
      - docker push registry.tech5-sa.com/t5-platform/t5-templates-db_app:$CI_COMMIT_REF_NAME
      - docker push registry.tech5-sa.com/t5-platform/t5-templates-db_postgresql:$CI_COMMIT_REF_NAME

    tags:
        - t5 
        - t5-templates-db


stage: test
        image: 
            name: postman/newman_alpine33
            entrypoint:[""]

        before_script: 
            - docker login -u "$CI_REGISTRY_USER" -P "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

        script: 
            - docker-compose up
            - newman --version
            - newman run ${POSTMAN_COLLECTION} -e ${POSTMAN_ENVIRONMENT}

【问题讨论】:

    标签: docker-compose dockerfile gitlab-ci gitlab-ci-runner


    【解决方案1】:

    我认为你是在正确的方式。只需添加另一个阶段,例如像这样部署:

    stages:
      - build
      - test
      - deploy
    
    build:
      stage: build
      script: echo "Building the app"
    
    test:
      stage: test
      script: echo "Running tests"
    
    deploy:
      stage: deploy
      script: echo "Deploying the app"
    

    分配给这些阶段的作业将按此顺序运行。如果任何作业失败,则管道将失败,分配给下一阶段的作业将不会运行。

    查看更多here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 2019-01-02
      • 2020-01-01
      • 2019-02-08
      • 2016-02-21
      • 2017-11-03
      • 2016-01-17
      相关资源
      最近更新 更多