azure-devops-cli-extension
azure-devops-cli-extension copied to clipboard
[Feature Request] az pipeline build queue wait for completion
Problem: it's complex to create a simple batch file which does something when the build is complete. Currently the batch file would need to handle the json response and poll status to determine build completion.
Proposal: Add az pipelines build queue --wait-for-build-complete. Block until build completes. A non-zero exit code would be returned if build is something other than successful. Very simple to sequence in a batch file.
Example batch file / check in script might be: git push az pipelines build queue --wait-for-build-complete if ERRORLEVEL 1 ( echo investigate it!!! exit /b 1 ) git pull init (etc)
To clarify, this is still automation use case, but the need is around simpler scripting that lets you eliminate potentially unnecessary polling right?
@geverghe Yes, that would make the automation easier.
The same parameter could also be added to az pipelines create
Thank you for the confirmation. We will evaluate how we can prioritize this ask based on the community feedback/reaction. Feel free to contribute as well - we can guide you in case you have any issues.
Proposal
- Include --wait as the parameter for indicating that the user wants to explicitly wait for the pipeline creation.
- Provide the same experience as that of az extension add to provide feedback that the command is undertaking an action at present Creating pipeline [pipeline name] ...
- Protection against long run time: @gauravsaralMs - could you advise the checks that need to be in place here?
With regard to long runtime, my suggestion is for the CLI run indefinitely by default (relying on the timeout on the invoked workflow), to avoid the surprise of having the CLI introduce a timeout-error to a long-running build process. (of course, control-C should cancel and exit with >0 exit code).
Consider workflows that have an extended stress test run or manual approval process that can run for days / weeks.
Hello guys, is there any news on this? Thanks!
Any update on this, please? It's 2021 already, you know.
As we don't have a way to wait for the completion of a pipeline, I am using the following wait logic (powershell). Hope this may help until the feature is available. :)
$buildQueue = (az pipelines build queue --organization $organization
--project $project `
--definition-name $definitionName) | ConvertFrom-Json
$buildNumber = $buildQueue.buildNumber
if ($null -ne $buildNumber)
{
# Get the status of triggered build
$buildDetails = (az pipelines build show --id $buildQueue.id
--detect true --organization $organization
--project $project) | ConvertFrom-Json
while ($buildDetails.status -ne "completed")
{
Start-Sleep -Seconds 10
if ($buildDetails.status -eq "notStarted")
{
$messageQueued = "$definitionName with build number $buildNumber is queued..."
Write-Host $messageQueued -ForegroundColor Green
}
if ($buildStatus -eq "canceled" -Or $buildStatus -eq "failed")
{
Write-Error "The build number $buildNumber is $buildStatus"
}
# Get the status of the triggered build again
$buildDetails = (az pipelines build show `
--id $buildQueue.id `
--detect true `
--organization $organization `
--project $project) | ConvertFrom-Json
}
}
Any update on this feature team? Thank you.
Adding my vote too here 👍 Sharing a similar waiting logic that works with bash ->
echo "Run the pipeline [$pipeline_name] from it's branch name [$branch_name]"
run=$(az pipelines run --organization "$organization_uri" --project "$project_name" --name "$pipeline_name" --branch "$branch_name")
TIMEOUT_SEC="60"
start_time="$(date -u +%s)"
result="null"
while [ "$result" != "succeeded" ]; do
current_time="$(date -u +%s)"
elapsed_seconds=$(($current_time-$start_time))
if [ $elapsed_seconds -gt $TIMEOUT_SEC ]; then
echo "ERROR: Timeout of [$TIMEOUT_SEC] sec with the build result [$result]"
exit 1
fi
build=$(az pipelines build show --organization "$organization_uri" --project "$project_name" --id $(echo "$run" | jq '.id'))
result=$(echo "$build" | jq -r '.result')
echo "Build result status is [$result], waiting 10 sec, elapsed [$elapsed_seconds] sec"
sleep 10
done
Is there any update on this feature?
This feature is really need it. Any updates?
Thanks @JamesDLD to post the bash script, it works really good!