在Ubuntu中集成Postman到CI/CD流程可以通过多种方式实现,以下是使用GitHub Actions的一个详细步骤指南:
Settings > Secrets and variables > Actions > New repository secrets
。.github/workflows
目录下创建一个新的YAML文件(例如 run-postman-tests.yml
)。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 }}
main
分支上推送更改时触发。postman-cli-tests
的任务。
将编辑好的工作流文件提交并推送到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流程中。