在 Jenkins 中,如何将 Web 请求正文作为参数传递给 Powershell 脚本?

In Jenkins, how do I pass a web request body as a parameter to a Powershell script?

所以在我的 Jenkins 管道中(使用通用 Webhook 触发器插件),我试图获取 POST 请求 JSON 正文并将其作为参数传递到 Powershell 脚本中。 Jenkins 管道中的 body 变量可以通过 echo body 访问,这很奇怪,因为它前面没有变量定界符 - 所以我不确定如何将它传递到脚本中。

注释行是我要执行的行。任何线索表示赞赏。谢谢!

node {
    echo body
    //powershell 'C:/Users/Ameera.Khan/Desktop/success_echo.ps1 -ArgumentList body'
}

尝试

{

echo body           // this `echo` is Jenkins step and Jenkins knows the var 
                    // named `body`, so it gets printed

bat 'echo body'     // this will print the string "body"

bat 'echo $body'    // this will print the content of (undefined) bat variable
                    // named `body`, so empty string

bat "echo ${body}"  // this will expand Groovy variable named `body` 
                    // and invoke `echo` on it
}

所以在你的情况下你可能想要

powershell "C:/Users/Ameera.Khan/Desktop/success_echo.ps1 -ArgumentList ${body}"