admin管理员组文章数量:1399022
I have an ADO pipeline which has a single job in it which sets some variables. I need a way to run this pipeline from the cli with a command like this:
run_id=$(az pipelines run --name "mypipeline" --branch "main" -- --project "myproject" --query "id" -o tsv)
Then I need a way to get the output variables from the cli with a command like this:
az pipelines runs show --id $run_id -- --project "myproject"
However, any attempt I make at getting a variable included in that output does not show up. Does anyone know if there's a way to get a variable outputted in a way that can be seen with an az pipelines runs show
command? I can easily pass variables between jobs, display them in the logs, etc. But I can't make them available to be seen from the cli.
I've tried many options of setting the variables like:
echo "##vso[task.setvariable variable=TEST1]test1"
echo "##vso[task.setvariable variable=TEST2;isOutput=true]test2"
echo "Output Variable: test3"
But none of them are ever included.
I have an ADO pipeline which has a single job in it which sets some variables. I need a way to run this pipeline from the cli with a command like this:
run_id=$(az pipelines run --name "mypipeline" --branch "main" -- https://dev.azure/MYORG --project "myproject" --query "id" -o tsv)
Then I need a way to get the output variables from the cli with a command like this:
az pipelines runs show --id $run_id -- https://dev.azure/MYORG --project "myproject"
However, any attempt I make at getting a variable included in that output does not show up. Does anyone know if there's a way to get a variable outputted in a way that can be seen with an az pipelines runs show
command? I can easily pass variables between jobs, display them in the logs, etc. But I can't make them available to be seen from the cli.
I've tried many options of setting the variables like:
echo "##vso[task.setvariable variable=TEST1]test1"
echo "##vso[task.setvariable variable=TEST2;isOutput=true]test2"
echo "Output Variable: test3"
But none of them are ever included.
Share Improve this question edited Mar 25 at 22:16 bryanbcook 18.7k2 gold badges47 silver badges79 bronze badges asked Mar 25 at 18:24 Gary TurnerGary Turner 3793 silver badges17 bronze badges1 Answer
Reset to default 1The purpose of "output variables" is to create state that can be reused between jobs or stages within the pipeline. They are not a direct by-product of the pipeline that can be queried, but there are other APIs that can expose that state.
The cli is a wrapper around the Azure DevOps REST API. Specifically, az pipeline runs show
calls the Build - GET endpoint. This endpoint gives you the details about which pipeline was run and its current status. The internal state of the pipeline, including the number of stages, jobs and tasks are not included in this endpoint.
The Timeline - GET endpoint can retrieve a flat list of all the stages, checks, jobs and tasks for a given build. Again, here, this is providing you with the status of those elements, not their outputs.
Once you have the Timeline, you can query an endpoint to give you specific details for a record.
The process looks like this:
Call the Timeline - GET endpoint to retrieve the timeline for the build.
https://dev.azure/<anization>/<project-id>/_apis/build/builds/<build-id>/timeline?api-version=7.1
This returns the current timeline for the build.
{ "id": "<timeline-id>", "records": [ { "id": "<record-id>", "parentId": "<record-id ref>", "type": "...", "name": "...", "state": "...", "result": "..." }, ... ] }
The output variables aren't exposed in this endpoint. Make note of the
id
.While there is a
Records - Update
endpoint to manipulate the record, the GET equivalent appears in the client libraries. The undocumented GET endpoint is:https://dev.azure/<anization>/<projectId>/_apis/distributedtask/hubs/build/plans/<planId>/timelines/<timelineId>/records/
Where the
planId
andtimelineId
is theid
of the timeline obtained in the last step.The JSON result looks similar to the Timeline - GET, except the output variables are included:
{ "value": [ ... { "id": "<id>", "type": "Task", "name": "...", "log": { ... }, "task": { ... }, "variables": { "MYVARIABLE1": { "value": "...." }, "MYVARIABLE2": { "value": "..." } } }, ... ] }
It is possible to invoke these calls using the az devops invoke
command.
$projectName = "<name>"
$projectId = "<guid-for-project>"
$buildId = 12345
$taskName = "<my_task_with_output_variables>"
# get the timeline for the build
$timeline = az devops invoke `
--area build `
--resource timeline `
--route-parameters `
project=$projectName `
buildId=$buildId | ConvertFrom-Json
$task = $timeline.records |
where-object { $_.type -eq "Task" -and $_.name -eq $taskName }
$timelineId = $timeline.id
$planId = $timeline.id
# get the timeline record
$record = az devops invoke `
--area distributedTask `
--resource records `
--route-parameters `
hubName="build" `
planId=$planId `
timelineId=$timelineId `
scopeIdentifier=$projectId | ConvertFrom-Json
# locate the task that has the output variables
$task = $record.value |
where-object { $_.type -eq "Task" -and $_.name -eq $taskName }
# party
write-output $task.variables.MYVARIABLE1.value
write-output $task.variables.MYVARIABLE2.value
本文标签: Access ADO Pipeline Output Variables using the Azure DevOps CLIStack Overflow
版权声明:本文标题:Access ADO Pipeline Output Variables using the Azure DevOps CLI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744175966a2594002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论