2
votes

How do you manage building from branches when using Azure DevOps Classic Build Pipelines and TFVC?

I believe that the only viable option is to copy the build pipeline with a new name and update the source code mapping to point to the new TFVC branch.

I see the ADO web UI provides the option to clone an individual build definition, yet as I have over 200+ build pipelines to clone whenever I branch is there a more efficient way to do this? Or is the only option to write a custom tool to leverage the ADO REST Api?

1
Hi @Techromancer. Is there any update about this ticket? Feel free to let me know if the answer could give you some help. Just a remind of this.Kevin Lu-MSFT
I was hoping for an answer that didn't require me writing a custom tool and neither to migrate to Git and YML builds (which looks the only supported option by MS! What happened to Tfvc parity with Git features?), nevertheless your example is really helpful, many thanks.Techromancer

1 Answers

1
votes

Since you need to clone pipelines in batches, using scripts to run the Rest API will be a reasonable method. As far as I know, there is no easy way out of the box other than this.

You could try the following PowerShell Script Sample:

$DefinitionIds = "PipelineIDs"  #InPut All Pipelineids(e.g. "324,323,xxx" )
$DefinitionId = $DefinitionIds.split(",");
$token = "PAT Token"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

foreach ($i in $DefinitionId)
{
echo $i

$url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/build/definitions/$($i)?api-version=6.0"


$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get  -ContentType application/json

Write-Host "$($response | ConvertTo-Json -Depth 100)"


$response.repository.properties.tfvcMapping= '{"mappings":[{"serverPath":"$/TFVCBranchName","mappingType":"map","localPath":"\\"}]}' # ServerPath is the Branch name

$response.repository.name = "TFVCRepoName" #Repo Source Name

$response.name = "Pipeline $i Clone" # Cloned PipelineName 

echo $response.name

$url1= "https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/build/definitions?api-version=6.0"


$json = @($response) | ConvertTo-Json -Depth 100

$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Post -Body $json -ContentType application/json


}

Here are the Two Rest APIs used in the Script:

Definitions - Get

Definitions - Create

Result:

The cloned Pipeline will be set to the new TFVC branch and Build definition name.

enter image description here