-1

I have a created a build pipeline in Azure DevOps and it is connected to one repo that I have in my Github. However, I want to connect/clone this build pipeline into any newly created repo in my github with a certain prefix in its name, like the word 'Build'.

MSOUFAN
  • 101
  • 2
  • 12

2 Answers2

1

You can navigate to your Build Pipeline, select the Option menu from the right hand side on the pipeline details page, and choose the Clone item.

You can then point the cloned build pipeline to your new Git repository and change the pipeline's name to have the prefix you wish.

Wim
  • 11,998
  • 1
  • 34
  • 57
  • Yes, I know that. I want to automate this process, so whenever I create a new github repo with the prefix, it clones the pipeline and connect it with it – MSOUFAN Nov 21 '19 at 18:03
0

Connecting Build pipeline in AzureDevOps to newly created repos with certain prefix Automatically

To automate the process, you need use the definition REST AP get the json body:

https://learn.microsoft.com/en-us/rest/api/azure/devops/build/definitions/get?view=azure-devops-rest-5.0

Then we could change the json file whatever we feel necessary, like Repository URL, change it to the new path for your newly created repo in my github.

At last, we could use create definition REST API with above Json file to create new pipeline:

https://learn.microsoft.com/en-us/rest/api/azure/devops/build/definitions/create?view=azure-devops-rest-5.0

$thisBuildDef.Name = $Clone_Name
$thisBuildDef.path = $BuildDefURL  # Relative to the Project name; like "Release/2019"
$thisBuildDef.buildNumberFormat = $BuildNumberFormat

# Update source control path to new branch
$defAsJson = $thisBuildDef | ConvertTo-Json -Depth 100
$defAsJson = $defAsJson.Replace($sourceControlMainline, $sourceControlBranch)

$Uri = "https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=2.0"

$newBuildDef = Invoke-RestMethod -Uri $Uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Post -Body $defAsJson -ContentType "application/json" -ErrorAction Stop

Check the document Using JSON via REST to create build definitions in VSO and the vsts-clone-build-with-powershell.ps1 sample.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thank you so much for your answer. That was very helpful. However, I want the repo creation process in github to call the Azure DevOps API that you mentioned. Do you know if this is feasible? – MSOUFAN Nov 25 '19 at 15:16