在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>
集成測試結果
自動化觸發與監控
參考來源: