azure-devops-cli-extension icon indicating copy to clipboard operation
azure-devops-cli-extension copied to clipboard

[Feature Request] az pipeline build queue wait for completion

Open merlynomsft opened this issue 5 years ago • 12 comments

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)

merlynomsft avatar Aug 08 '19 17:08 merlynomsft

To clarify, this is still automation use case, but the need is around simpler scripting that lets you eliminate potentially unnecessary polling right?

geverghe avatar Aug 28 '19 06:08 geverghe

@geverghe Yes, that would make the automation easier. The same parameter could also be added to az pipelines create

jwikman avatar Aug 28 '19 10:08 jwikman

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.

geverghe avatar Aug 29 '19 09:08 geverghe

Proposal

  1. Include --wait as the parameter for indicating that the user wants to explicitly wait for the pipeline creation.
  2. 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] ...
  3. Protection against long run time: @gauravsaralMs - could you advise the checks that need to be in place here?

geverghe avatar Oct 15 '19 13:10 geverghe

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.

merlynomsft avatar Oct 15 '19 15:10 merlynomsft

Hello guys, is there any news on this? Thanks!

maonat avatar Jun 05 '20 14:06 maonat

Any update on this, please? It's 2021 already, you know.

abatishchev avatar Jan 30 '21 20:01 abatishchev

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
}		

}

sanoopkarakkat avatar Feb 05 '21 14:02 sanoopkarakkat

Any update on this feature team? Thank you.

rikkigouda avatar Aug 04 '22 04:08 rikkigouda

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

JamesDLD avatar Nov 28 '23 15:11 JamesDLD

Is there any update on this feature?

rajvi avatar Dec 29 '23 21:12 rajvi

This feature is really need it. Any updates?

Thanks @JamesDLD to post the bash script, it works really good!

osroflo avatar Jan 05 '24 03:01 osroflo