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

Add ability to poll for task availability after install

Open charleszipp opened this issue 3 years ago • 4 comments

For my extension, i run several tests after install a pre-release version to testing org. I have noticed that there is a delay after installing an extension before it can actually be used. I have found that polling the tfx build tasks list for my task id allows my pipeline to know when the task is ready for use. Having either the install task or a new task perform this check may be helpful to others that are experiencing the same. Here is the bash I use to poll for task availability from my pipeline. I think the same could be done from node much easier

#/bin/bash
set -e

task_id=
token=
service_url=
attempts=0
max=25

while getopts t:s:c: flag; do
    case "${flag}" in
        t) token="${OPTARG}";;
        s) service_url="${OPTARG}";;
        c) task_id="${OPTARG}";;
    esac
done

until $(npx tfx build tasks list --service-url $service_url -t $token --no-color --json |  jq -r --arg t "$task_id" '.[] | select(.id == $t) | .id' | grep -q "$task_id");
do
    if [ $attempts -gt $max ]
    then
        echo "wait limit reached! exiting..."
        return 1;
    else
        echo "waiting for task to become available..."        
        sleep $(( attempts++ ));
    fi
done

echo "task is available!"

charleszipp avatar Mar 02 '21 20:03 charleszipp

Here is the error I get if i try to use the tasks too quickly after install. If I rerun the jobs a few minutes later, they work fine

##[error]A task is missing. The pipeline references a task called '<my-task-id>'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com.

charleszipp avatar Mar 02 '21 20:03 charleszipp

Yeah, this is frustrating. Richard Fennel has a release gate that waits for the availability.

In order for this to be really useful, you probably also want the exact same version to be available.

I currently don't have the bandwidth to add this though. I'll keep it in mind for future enhancements.

jessehouwing avatar Mar 03 '21 16:03 jessehouwing

https://blogs.blackmarble.co.uk/rfennell/2018/03/20/using-vsts-gates-to-help-improve-my-deployment-pipeline-of-vsts-extensions-to-the-visual-studio-marketplace/

jessehouwing avatar Mar 03 '21 16:03 jessehouwing

Thanks @jessehouwing for the additional solution and the feedback about the version.

charleszipp avatar Mar 03 '21 16:03 charleszipp