ubuntu

Postman在Ubuntu中如何集成CI/CD

小樊
35
2025-04-09 09:01:34
栏目: 智能运维

在Ubuntu中集成Postman到CI/CD流程可以通过多种方式实现,以下是使用GitHub Actions的一个详细步骤指南:

在Ubuntu中集成Postman到CI/CD的步骤

  1. 创建GitHub仓库并添加API密钥
  1. 创建GitHub Actions工作流
  1. 编写工作流文件: 以下是一个示例工作流文件的内容:
name: Run Multiple Postman Collections and Save Reports

on:
  push:
    branches:
      - main

jobs:
  postman-cli-tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        config:
          - { collection_id: "40443175-0e230280-1eea-45ad-b7e4-2c6316a91b62", environment_id: "40443175-1c302d5e-5930-4579-880f-ce404a2c4b29" }
          - { collection_id: "40443175-85560488-42ec-4d0e-b866-fda8ca231b15", environment_id: "40443175-55f8a2ab-0dc1-48a9-8279-59b370c19d78" }

    steps:
      # 代码检出
      - name: Checkout code
        uses: actions/checkout@v2

      # 安装Postman CLI
      - name: Install Postman CLI
        run: |
          curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh

      # 登录到Postman CLI
      - name: Login to Postman CLI
        run: |
          postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }}

      # 运行Postman集合并生成报告
      - name: Run Collection and Generate Report
        run: |
          postman collection run ${{ matrix.config.collection_id }} \
            --environment ${{ matrix.config.environment_id }}

解释工作流文件的各个部分

提交并推送工作流文件

将编辑好的工作流文件提交并推送到GitHub仓库:

git add run-postman-tests.yml
git commit -m "Add GitHub Actions workflow for running Postman tests"
git push origin main

验证工作流

推送更改后,GitHub Actions将自动触发工作流,并在Actions标签页中显示运行结果。你可以通过这些结果来验证Postman测试是否成功执行。

通过这种方式,你可以在Ubuntu中通过GitHub Actions自动化Postman测试的集成到CI/CD流程中。

0
看了该问题的人还看了