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

时间:2018-04-19 19:29:11

标签: .net powershell jenkins postman newman

我能够从常规PowerShell执行newman命令而不会出现问题:

enter image description here

但是,当我让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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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

npm install -g newman

调用您的集合:纽曼(Newman)运行examples / sample-collection.json

或使用纽曼作为库

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!');
});