VSTS build from multiple repositories

2020-03-01 08:25发布

问题:

I have two repositories - one in TFVC and another in Git. There are specific technical reasons for keeping them separate.

The code in TFVC is built on a private build agent and the code in Git is built on a hosted agent. So currently I have two independent builds and the outcomes of them are deployed together in a release definition.

I am looking at creating builds that may be able to get the source from both the repositories so that I have a single build definition to manage.

Is there a way to achieve this?

回答1:

For now, there is no way to specify multiple repositories in Get sources step. And there has an user voice Allow TFS build to depend on multiple repositories which suggests similar feature, you can vote and follow up.

The workaround for now is manually get the files from the other repo.

Such as, if you specify TFVC repo in Get sources step, then you can add a PowerShell task at the beginning of the tasks, and clone the other git repo by git clone <repo URL> etc.



回答2:

TFVC

And the inverse of Marina's answer is also possible. After binding your build definition to Git by default, you can add a powershell script to map a workspace and fetch the sources:

tf workspace /new /noprompt /location:local /permission:private <name>
tf workfold /map $/Server/Path "$(Agent.BuildDirectory)\tfvc" /workspace:<name>
tf get "$(Agent.BuildDirectory)\tfvc"

And add a "always run task" to clean up the workspace afterwards:

tf workspace /delete <name>
rd /s /q "$(Agent.BuildDirectory)\tfvc"

Download artifact

Another option is to use the Download Artefact task to download the artifacts from the following extension: TFS Artifacts for Release Management.

Or the Download Artifact task that comes with VSTS, though that one requires a link to a Build Definition to download from, which means you could have a CI build on either Git or TFVC that build the sources, or simply attaches the sources directory, then fetch those in the "other" build.



回答3:

Do you actually want to build both repos simultaneously and get the build artifacts mixed together? Or do you just want to use the same definition to target different sources?

If you really want the first, you can script the fetching of sources during the build as the other answers have pointed out. However, if building Git on hosted and TFVC on private is a hard requirement, building both sets of sources simultaneously will fail this.

I would recommend creating a Task Group with the tasks you have in common. Then create separate build definitions that reference the task group.