从管道调用Powershell变量

时间:2017-07-26 16:10:22

标签: python rest powershell jenkins jenkins-pipeline

我在Jenkins中使用管道运行构建。 我陷入困境,我正在使用Powershell调用REST方法,我希望打印出REST调用的结果。

到目前为止,这是我的代码

stage ('Call Powershell Script')
{
    node {
        powershell '$result = Invoke-RestMethod -Uri http://127.0.0.1:5000/doanalysis -Method Post -Body @{repo="DataCollection";pr="23";source="master2";destination="master"}'
        powershell 'Write-Host $result'
    }
}

REST调用正常运行。它实际上是对我使用Flask设置的Web应用程序进行调用。 但是,我无法正确显示输出。输出应该只是一个字符串。 我控制了Web应用程序,所以我可以返回任何必要的格式。

[Pipeline] stage
[Pipeline] { (Call Powershell Script)
[Pipeline] node
Running on master in C:\Program Files (x86)\Jenkins\jobs\PR Projects\jobs\PR Pipeline2\workspace
[Pipeline] {
[Pipeline] powershell
[workspace] Running PowerShell script
[Pipeline] powershell
[workspace] Running PowerShell script

[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline

此外,如果我只是尝试回复$ result'在Powershell之外,它表示它并不存在。

有没有办法从管道进行REST调用?我使用Jenkins,所以我可以访问Jenkins上的管道插件。 有没有办法让我从管道中访问powershell中的变量? 或者有什么方法可以解决我目前正在做的事情吗?

提前致谢

0 个答案:

没有答案