Azure Devops管道构建参数



下面的代码是一个API调用,它将运行azure管道,但我遇到的唯一问题是我无法在自定义分支上运行它,我尝试过az命令,但使用az命令时,无法传递参数。我的目标基本上是我有一个管道a,我想运行管道B,这不介意,所以我不能编辑它,但管道B接受了一个名为Tag的参数,我想从Pineline a传递它,但很难做到。


$token = -join("$Username", ":", "$PAT")
$headers = @{ 
Authorization = "Basic "+ [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($token))
'Content-Type' = "application/json"
}
$uri = "https://dev.azure.com/{$Company}/{$Team}/_apis/pipelines/{$ProjectID}/runs/?api-version=6.0-preview.1"
$pipelineBody=@{
resources=@{
repositories=@{
self=@{
ref="$Branch"
}
}
}
templateParameters=@{
Tag="$Tag"
}
} | ConvertTo-Json
$result = Invoke-WebRequest -Uri $uri `
-Headers $headers `
-Body "$pipelineBody" `
-Method Post `
#-SkipCertificateCheck `
#-SkipHttpErrorCheck `
#-ErrorAction Stop
if($result.StatusCode -ne "200")
{
throw $result
}
return ($result.Content | ConvertFrom-Json).url

您可以通过以下步骤来实现这一点(而不是直接实现您想要的(:

  • 为管道A(阶段1(和管道B(阶段2(创建单个管道
  • 添加管道a(阶段1(对管道B(阶段2(的依赖项,该依赖项仅在管道a成功时运行
  • Stage 1中使用Powershell脚本将管道变量设置为您试图为Stage 2设置的值-在ADO的Powershell脚本任务中使用out变量
  • 在(管道B的(所需步骤中使用上面设置的管道变量

最新更新