如何在 .gitlab-ci.yml 文件中将预部署脚本写入 运行 newman postman 测试

How do I write pre-deployment scripts to run newman postman test in .gitlab-ci.yml file

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

这是我的 .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}

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

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