代码之家  ›  专栏  ›  技术社区  ›  DDiVita

使用newman/postman设置输出变量被切断

  •  0
  • DDiVita  · 技术社区  · 8 年前

    siteToDeploy 和 siteToStop . 我正在使用postman对IIS管理API运行测试脚本。在其中一个请求的测试部分,我试图设置azure devops输出变量。这是一种工作方式,但由于某种原因,变量值被切断了。

    log(pm.globals.get(“siteName”))

    var response = pm.response.json();
    
    var startedSite = _.find(response.websites, function(o) { return o.name.indexOf(pm.globals.get("siteName")) > -1 && pm.globals.get("siteName") &&  o.status == 'started'});
    var stoppedSite = _.find(response.websites, function(o) { return o.name.indexOf(pm.globals.get("siteName"))  > -1 &&  o.status == 'stopped'});
    
    if(stoppedSite && startedSite){
    
        console.log('sites found');
    
        console.log(stoppedSite.id)
        console.log('##vso[task.setvariable variable=siteToDeploy;]' + stoppedSite.id);
        console.log('##vso[task.setvariable variable=siteToStop;]' + startedSite.id);
    }
    

    Newman

    下面是一个命令行任务的输出,它回显$(siteToDeploy)变量。它正在设置,但不是整个值。 enter image description here

    我试过逃避,但没有效果。我还创建了一个静态命令行echo,其中设置了变量,效果很好。因此,我不确定这是纽曼问题还是Azure在获取变量时遇到问题。

    1 回复  |  直到 8 年前
        1
  •  0
  •   DDiVita    7 年前

    问题变成了Azure如何解析Newman控制台日志输出。我不得不添加一个额外的Powershell任务来替换 '

    这就是它看起来的样子:

    ##This task is only here because of how Newman is writing out the console.log 
    Param(
    [string]$_siteToDeploy = (("$(siteToDeploy)") -replace "'",""),
    [string]$_siteToStop = (("$(siteToStop)") -replace "'","")
    )
    Write-Host ("##vso[task.setvariable variable=siteToDeploy;]{0}" -f  ($_siteToDeploy))
    Write-Host ("##vso[task.setvariable variable=siteToStop;]{0}" -f ($_siteToStop))
    
    推荐文章