在 Ubuntu 上“跑 Postman 脚本”通常有两种理解,下面分别说明,你可以按需要选择。
Postman 官方在 Linux 上没有好用的命令行 GUI 脚本执行方式,标准做法是:
用 Postman 导出 Collection → 用 Newman 跑
sudo apt update
sudo apt install -y nodejs npm
验证:
node -v
npm -v
sudo npm install -g newman
验证:
newman --version
... → Exportcollection.json(如果有环境变量,也导出 environment.json)
newman run collection.json
带环境变量:
newman run collection.json -e environment.json
生成 HTML 报告(可选):
npm install -g newman-reporter-htmlextra
newman run collection.json -r htmlextra
如果你只是想在 Ubuntu 上用 Postman 界面跑请求:
sudo apt install -y wget gpg
wget -qO - https://dl.postman.co/schema/keyring.gpg | gpg --dearmor > postman.gpg
sudo install -D -o root -g root -m 644 postman.gpg /etc/apt/keyrings/postman.gpg
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/postman.gpg] https://dl.postman.co/repo/apt/ stable main" | sudo tee /etc/apt/sources.list.d/postman.list
sudo apt update
sudo apt install postman
启动:
postman
sudo snap install postman
这些不能单独跑,必须:
例如:
// Tests 脚本
pm.test("status is 200", () => {
pm.response.to.have.status(200);
});
newman run collection.json -e env.json --reporters cli,junit
可接 Jenkins / GitLab CI / GitHub Actions。
如果你能具体说一下:
我可以直接给你一条完整可复制的命令。