在Linux系统中集成Postman与CI/CD流程,可参考以下步骤:
准备工具与依赖
npm install -g newman。创建API测试集合
collection.json)。配置CI/CD工具
Jenkinsfile中定义步骤:拉取代码→安装newman→运行测试集合→生成报告(如JUnit格式)。pipeline {
agent any
stages {
stage('Run Postman Tests') {
steps {
sh 'npm install -g newman'
sh 'newman run "collection.json" --reporters cli,junit --reporter-junit-export report.xml'
}
}
stage('Publish Results') {
steps {
junit 'report.xml'
}
}
}
}
.github/workflows目录创建YAML文件(如postman.yml),定义触发条件(如push事件)。postman/login-action登录,运行集合并生成报告。name: Run Postman Tests
on: push: branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Login to Postman
uses: postman/login-action@v1
with:
api-key: ${{ secrets.POSTMAN_API_KEY }}
- name: Run Collection
run: postman collection run <collection_id> --environment <environment_id>
集成测试结果
自动化触发与监控
参考来源: