0

我可以newman毫无问题地从常规 powershell 执行命令:

在此处输入图像描述

但是,当我让 Jenkins 运行相同的脚本时,我得到以下输出:

Checkinig prerequisites
   Chocolatey is already installed
   NodeJS is already installed
   NPM is already installed
Starting collection tests

  Testing  C:\Program Files (x86)\Jenkins\workspace\GenericServiceWithPostman\Collections\Account Recv Microservice.postman_collection.json
newman : The term 'newman' is not recognized as the name of a cmdlet, 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At C:\Program Files 
(x86)\Jenkins\workspace\GenericServiceWithPostman\RunColletionTests.ps1:47 
char:1
+ newman run $test.FullName --environment .\Environments\DEV01.postman_ ...
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (newman:String) [], CommandNotFo 
   undException
    + FullyQualifiedErrorId : CommandNotFoundException

我运行的脚本:

$tests = gci .\Collections\*postman_collection.json| Select-Object -Property FullName

foreach ($test in $tests)
 { 
 Write-Host ""
Write-Host "  Testing " $test.FullName
Start-Sleep -s 5 
newman run $test.FullName --environment .\Environments\DEV01.postman_environment.json
}

术语“newman”未被识别为 cmdlet 的名称

我究竟做错了什么?我如何让它看到newman

4

2 回答 2

2

无论运行 Jenkins,它看起来newman都没有在它的路径上。在 Jenkins 的服务帐户上下文下,尝试where.exe newman. 如果它在路径中,它应该返回程序的位置。

于 2018-04-19T19:39:03.593 回答
0

你应该安装https://www.npmjs.com/package/newman

npm install -g 纽曼

调用您的收藏: newman run examples/sample-collection.json

或使用 newman 作为库

const newman = require('newman'); // 在你的项目中需要 newman

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: require('./sample-collection.json'),
    reporters: 'cli'
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});
于 2020-06-01T16:27:48.103 回答