CentOS 与 Postman 集成方案
一 安装与部署选项
sudo tar -xzf Postman-linux-x64-*.tar.gz -C /optsudo ln -s /opt/Postman/Postman /usr/bin/postmanpostmansudo yum install -y nodejs npmsudo npm install -g newmannewman run collection.json -e environment.jsonsudo yum install snapd && sudo systemctl enable --now snapd.socket && sudo ln -s /var/lib/snapd/snap /snap,随后 sudo snap install postman --classicsudo yum install postman(以仓库实际提供为准)。二 自动化与 CI/CD 集成
newman run collection.json -e environment.jsonnewman run collection.json -e environment.json -r cli,html,json#!/usr/bin/env bash
set -e
COLLECTION="/path/to/collection.json"
ENVIRONMENT="/path/to/environment.json"
REPORT_DIR="/var/reports/postman/$(date +%F_%H-%M-%S)"
mkdir -p "$REPORT_DIR"
newman run "$COLLECTION" -e "$ENVIRONMENT" -r cli,html,json --reporter-html-export "$REPORT_DIR/report.html" --reporter-json-export "$REPORT_DIR/report.json"
chmod +x run_postman.sh0 2 * * * /path/to/run_postman.sh >> /var/log/postman-runner.log 2>&1[Unit]
Description=Newman Postman Collection Runner
After=network.target
[Service]
Type=simple
User=postman
ExecStart=/usr/local/bin/newman run /path/to/collection.json -e /path/to/environment.json -r cli,html,json
Restart=on-failure
WorkingDirectory=/opt/postman-runner
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now postman.service- name: Run Postman Collection
run: |
npm i -g newman
newman run collection.json -e environment.json -r cli,html,json --reporter-html-export report.html
- name: Upload Report
uses: actions/upload-artifact@v4
with:
name: postman-report
path: report.html
三 安全与合规建议
四 常见问题与排查
ls -l /usr/bin/postman;必要时重新创建软链或将 /opt/Postman 加入 PATH。npm i -g newman 重装;查看报错日志定位依赖或网络问题。