Manuel S
Manuel S

Reputation: 43

Using semaphore-like conditions for pipeline job queueing

we use floating licenses for our more expensive compilers/tools, so that we can do local development as well as our production builds. The license manager (flexLM) has an api we can query, so we could block the license. However, I cannot find a mechanism by which I can cause my pipeline to queue based on the state of an auxiliary variable or return value of a script or something like that.

This means that I can launch the build on any machine on which the compiler is installed but it will then fail if the license is not available and I will have to relaunch the pipeline. If I did that automatically I would effectively just block that machine until the license becomes available.

Is there anything I have missed that could achieve a "queueing until license becomes available" kind of thing?

Thank you, Manuel

Upvotes: 1

Views: 516

Answers (1)

Vito Liu
Vito Liu

Reputation: 8298

We can add the first task power shell in the pipeline definition and define new variable in the variable tab such as Value:true, then add script to check the license status, if the license is available, set the variable Value to true, if the license is not available, set the variable Value to False. Then add condition eq(variables['{variable name}'], '{variable value}') in the Second task.

After configure, if your license is available, the pipeline will run successfully.

Or we could check the license first, then call the below script to queue build pipeline.

$token = "$(pat)"
$url = "https://dev.azure.com/{Org name}/{project name}/_apis/build/builds?api-version=6.1-preview.6"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))


$JSON = @"
{
  "definition": {
    "id": {Build definition ID}
  }
}
"@

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
write-host $response

Upvotes: 2

Related Questions