Search code examples
gitazure-devopsazure-pipelinesazure-devops-server-2019

Azure Devops Server: How to setup build pipeline to get git sources as a task instead of geting it automatically


I'm trying to make some builds more efficient by spliting them into multiple agent steps. First step will build our entire product, with unit tests and all and create an artifact containing unit tests, and two or more subsequent steps will run different parts of the unit test suites.

So far so good, everything works fine but all build agent steps gets the git sources, even though it is only neccessary for the first step. That takes another 1½ minutes that could have made the build even more efficient, and takes away some of the points of making it even more efficient (multiple build agents per step will not improve performance much, since all of them gets the sources for 1½ minutes first).

I've found the "Don't sync sources" checkbox for the Get Sources step in the pipeline, and that makes it so that the build steps no longer gets sources. But I DO want to get sources for the first build step, so now I have to do that manually?

I've tried to mimic what the Get Sources step does (according to the logs) in a Command Line-task but I cant quite get it to work. I've also tried manually setting up the git repo other ways via command line, and for some configurations it works, but for some it doesn't. It should work for normal branches, nested branches and PR-branches, but I feel like I'm missing something in the way git works to get the task to do proper work.

How do I setup a Get Sources step for Git in a proper way?


Solution

  • The easy way is to install the Git Repository Downloader extension from the marketplace and use it in the first task.

    enter image description here

    Another option is to use a Command Line task and rungit clone.

    For authentication you have 2 options:

    1. Put the password in the command:

    git clone https://username:password@dev.azure.com/organization/project/_git/repo

    1. Create a Personal Access Token and put it in the command:

    git clone https://PAT@dev.azure.com/organization/project/_git/repo