通过Powershell将多个参数发送到Azure-Devops管道作业 [英] send multiple parameter to Azure-Devops pipeline job via Powershell

查看:64
本文介绍了通过Powershell将多个参数发送到Azure-Devops管道作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够启动Azure Devops Build作业并发送文本参数,但是我似乎只能发送一个参数,而不能发送更多参数.我需要发送一个可以正常工作的令牌参数Ok,但我还想发送一个文本参数,其中包含要由Build作业中的Powershell脚本处理的json有效负载.所以我有一个Hellow World定义设置,在Pipeline变量中有两个变量.第一个是令牌文本,第二个是jsonInput.两者都具有复选框可在队列时间设置".检查.我的作业定义中有一个PowerShell Inline脚本,它是这样的:

 写入主机"Hello World"写主机令牌文本:$(tokentext)`n";写主机"Json Input"写主机" ---------------------------------------------------"$(jsonInput) 

我发送给Invoke-RestMethod的身体是:

  $ body = @ {定义= @ {id = $ buildDefID}参数="{`""tokentext`":$ mytoken}{`"jsonInput`":$ j}"}$ b = $ body |转换成杰森 

这有效,但以上方法无效:

  $ body = @ {定义= @ {id = $ buildDefID}参数="{`""tokentext`":$ mytoken}"}$ b = $ body |转换成杰森 

我尝试用逗号分隔参数等.所有尝试过的东西我都尝试过.如果有人要通过脚本为构建定义中的变量设置多个参数,我肯定会提供一些帮助.

谢谢

解决方案

下面的请求正文对我有用.请检查一下.

  $ body = @ {定义= @ {id = $ buildDefID};参数="{""jsonInput`":" $ jsonInput`","tokentext"":"$ tokentext""}".}$ b = $ body |转换成杰森 

您还可以通过 解决方案

Below request body works for me. Please check it out.

$body = @{
  definition= @{id = $buildDefID};

  parameters ="{`"jsonInput`":`"$jsonInput`", `"tokentext`":`"$tokentext`"}"
 }
$b = $body  | ConvertTo-Json

You can also run your pipeline via Runs - Run Pipeline rest api which is less complicated.

POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.1-preview.1

pipelineId is the $buildDefID

You can put the parameters in your request body as below:

 $body=@{
     
     variables = @{
 
         jsonInput= @{value = $jsonInput};
     
         tokentext= @{value = $tokentext}
      }
  }

$b = $body  | ConvertTo-Json

这篇关于通过Powershell将多个参数发送到Azure-Devops管道作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆