Reputation: 524
my query is How to pass parameters to azure Dev ops build pipeline externally to control the tasks execution? To explain in detail heres the explanation:
I have a project in the azure Dev ops which has a build pipeline configured with some series of tasks involving building the solution, generating deployable package and etc. Usually this is getting executed well and good without any issues.
What I want to achieve is declare a pipeline variable in this project build definition that I can access externally when I say it is some thing like an altogether different or External application like ms flow so that I can pass a value to the newly created pipeline variable as stated above and using this value stored in this new variable I should be able to skip few steps in the build pipeline andi should be able to execute only few steps.
Let me explain with an example:
The query is how to achieve or make this kind of behaviour to happen?
Please help me out in solving this issue?
If passing the value to variable is not possible, can you please let me know how to achieve the skipping behaviour in azure Dev ops build pipeline triggered from external application like ms flow?
Upvotes: 2
Views: 4745
Reputation: 1407
Since there is a REST API can pass parameters when queue a build and you can specify custom conditions in your build pipeline, there is a workaround. According to the REST API documentation, you can convert it to Powershell script like below.
Param(
[string]$collectionurl = "https://dev.azure.com/{orgname}",
[string]$project = "{projectname}",
[string]$user = "{useraccount}",
[string]$token = "{yourPAT}"
)
$base64AuthInfo= [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $token)))
$defurl = "$collectionurl/$project/_apis/build/builds?api-version=5.0"
$json = '{"parameters": "{\"AnotherParameter\": \"true\"}","definition": {"id": "{definitionId}"}}'
$updatedef = Invoke-RestMethod -Uri $defurl -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
You can create three build pipelines. The first pipeline is your main pipeline which has 5 different tasks. You can set the custom condition like below. It means, only when the value of AnotherParameter is true, the task will run.
The second pipeline and the third pipeline is the trigger pipeline. In the second pipeline, you can use powershell script to set the AnotherParameter as false and in the third pipeline, set the value as true.
Then set the second pipeline is triggered by external application and the third pipeline is triggered by your repo or others.
When the external application triggered the second pipeline, the value of AnotherParameter will be false and some of tasks in the first pipeline will not run.
When the third pipeline is triggered by your commit, the value of AnotherParameter will be true and all of task in the first pipeline will run as expected.
Upvotes: 2
Reputation: 310
You can call the Azure DevOps REST API and pass parameters in the request. Take a look at this post for more information: Start a build and passing variables through VSTS Rest API
If you want to add a condition to a task or a build pipeline, check out the documentation for conditions: Conditions - Azure Pipelines
Upvotes: 0