【问题标题】:Do I need to install newman on my desktop if I want to run a newman command in Gitlab?如果我想在 Gitlab 中运行 newman 命令,是否需要在桌面上安装 newman?
【发布时间】:2021-04-01 13:35:25
【问题描述】:

我是 Gitlab、newman 和 docker 的新手,我正在参加关于如何将所有内容集成在一起的速成课程。

在我的桌面(Windows 操作系统)上,我安装了 newman,并设法通过 Windows 命令行运行“newman run [postman collections]”。

我最终想要做的是在 Gitlab 中运行一个 newman 命令。 在 .gitlab-ci 中,我有这个:

stages:
      - test

Test_A: 
     stage: test
     image: postman/newman
     script:
     - newman run Collection1.json

想到几个问题:

  1. 我是否还需要在 .gitlab-ci 文件中运行“npm install -g newman”命令? 如果不是,Gitlab 怎么知道 newman 命令的语法? 示例:newman run

  2. 我需要在我的 .gitlab-ci 文件中为 docker 指定一个命令吗? 示例:docker pull postman/newman

更新#2

stages:
      - test

before_script:
     - npm install -g newman
     - npm install -g npm

Test_A: 
  stage: test
  script: 
    - newman run Collection1.json

【问题讨论】:

  • 您需要在管道中安装所有依赖项才能运行测试。如果你的测试是 dockerized,你只需要拉取镜像并运行一个包含测试的容器。如果你的测试没有 dockerized,你需要安装 node 和 newman。
  • 嗨@pavelsaman,谢谢你的信息。好的,我的测试没有 dockerized,这意味着我需要在管道中安装 node 和 newman。像这样的东西?更新#2。
  • 是的。你可以在这里获得灵感medium.com/@autumn.bom/…

标签: docker gitlab yaml postman newman


【解决方案1】:

首先要确定 GitLab 管道的执行方式。

我个人的选择是使用基于 Docker 的运行器。

如果您使用 GitLab docker-runner 来运行管道,那么您只需在 .gitlab-ci.yml 文件中定义您的容器映像。

这是一个经过测试(在 GitLab.com 上)的管道 yml 版本

stages:
   - test

run_postman_tests: 
    stage: test
    image: 
      name: postman/newman
      entrypoint: [""] #This overrides the default entrypoint for this image.
    script:
      - newman run postman_collection.json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-12
    • 2022-09-26
    • 1970-01-01
    • 2021-10-29
    • 2022-06-22
    • 2021-12-26
    • 2019-11-26
    • 2019-07-20
    相关资源
    最近更新 更多