0

We use Azure DevOps Server 2020 on prem. We are not in a position to move to Services. We are not in a position to use agents in Azure, because these agent would not be able to talk to the server, which is behind the corporate firewall.

So, we are stuck with on-prem agents and this suffocates us. Our app is a monolith in the worst sense of the word. Its PR build takes time and is extremely hungry on resources. Currently we have 2-3 PR builds running concurrently on the same machine and it takes eternity. In short - it is very bad.

On the other hands, developers have pretty powerful machines. Of course, I do not want my machine to serve PR builds of others, but if it could run my own PR build, that would be fantastic.

Alas, I do not see how this can be done. So, my question - is it possible to configure Azure DevOps Server 2020 so that PR validation build for a PR submitted by Alice would run on the build agent running on Alice's machine and only if there is no such agent would it pick up a "standard" build agent running on a build server?

Clarification

Although the question speaks about Alice, but there are also Bob and Charlie and Deepak. About 300+ developers. So, the solution should not assume there is only one developer working on the code.

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

1

is it possible to configure Azure DevOps Server 2020 so that PR validation build for a PR submitted by Alice would run on the build agent running on Alice's machine

We could install the self-hosted agent in the Alice's machine, open Organization Settings->Agent pools->select the agent->click the tab Capabilities->search the field Agent.ComputerName, then open PR build definition and add Demands, such as below.

Then the PR build will run with the specified agent, you could check this doc: Specify demands for more details.

In addition, if the PR build does not find the matching agent, the build will not run with another agent.

enter image description here

Update1

Each developers have their owner agent on their owner’s machine, right?

Check this doc: predefined variables, it contain the variable Build.RequestedFor and Build.RequestedForEmail, if the pipeline is pull request trigger, it will show the pull request creator name and email, add this to the pipeline Demands. Such as

enter image description here

And then, let all developers add capabilities to their agents, such as TriggerName = {their email or display name}. Since I am using the variable Build.RequestedForEmail, in my agent, I add the capabilities:

enter image description here

Then if I create a pull request, the build will run via my own machine agent.

Update 2

For example, the original PR build name is A. Open it and add default demand(you could add anything)

Add new build definition name B, add task power shell and enter power shell script to call below REST API to update the A definition

Definitions - Get

GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.1-preview.7

Definitions - Update

PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.1-preview.7

Then add build B as pull request build.

Update3

is it possible to configure Azure DevOps Server 2020 so that PR validation build for a PR submitted by Alice would run on the build agent running on Alice's machine and only if there is no such agent would it pick up a "standard" build agent running on a build server?

If the "real" targets the build agent initially, then what happens when the auxiliary one determines the dev has an individual agent?

The real build definition has demands, If the build runs by default demands, it will run the standard build agent.

The auxiliary one, we need to add condition to run the power shell script to update the real build demands. if Alice's machine has matching agent, it will update the real build demands, and then the real build will run the Alice's machine agent.

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • Does your answer imply Alice has a PR build dedicated solely to her? Do I understand you correctly? – mark Apr 07 '21 at 15:03
  • Hi @mark, I have updated the answer, please check the update1 – Vito Liu Apr 08 '21 at 03:35
  • In addition, all developer should install the self-hosted agent in the same agent pool – Vito Liu Apr 08 '21 at 03:35
  • 1
    +1 - This is much better. However, I have a problem with all or nothing approach. I cannot expect all the developers to run the build agent. It must roll out gradually, because there are details to sort out. So the requirement to fall back on the "standard" agents running on the build server is important. – mark Apr 08 '21 at 15:03
  • Hi @mark, If this answer is helpful, would you please accept it as the answer? So it could help other community members who get the same issues and we could archive this thread. Thanks. Have a nice day. :) – Vito Liu Apr 09 '21 at 08:17
  • I am sorry, I cannot accept it as an answer, because it does not answer an important aspect of my question - please, see my previous comment. – mark Apr 09 '21 at 12:56
  • Hi @mark, There is no other solution except this workaround for the time being, you could add your request for this feature on our [UserVoice site](https://developercommunity.visualstudio.com/report?space=21&entry=suggestion), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps. – Vito Liu Apr 16 '21 at 06:37
  • Is it possible to tag the PR build dynamically? All the agents have demands - individual agents and fallback (i.e. build server) agents. But the PR build by default does not have any. The demand is added dynamically after the PR build is created based on whether the developer has an individual build agent. – mark Apr 16 '21 at 12:42
  • Hi @mark, check the update1, we could see that the Demands value is $(Build.RequestedForEmail), this value is the user mailbox that created the pull request, It is dynamic. If have any misunderstanding, could you please re-describe more details about scenario? Thanks. – Vito Liu Apr 19 '21 at 05:40
  • If you want to dynamically add Demands, we could create another build definition and add task power shell to get the Pull request build definition and then add this new build to the Build Validation. But we can't control the running order of pr build, maybe you need to re-queue original build again in the pull request page. – Vito Liu Apr 19 '21 at 05:45
  • The update 1 does not address the fallback requirement. It starts with a wrong premise - **Each developers have their owner agent on their owner’s machine, right?** No, **some** developers have agent running on their own machine. That is why the question requires fallback to a build server agent. Your last comment is more promising. Can you elaborate on that scheme? – mark Apr 19 '21 at 22:04
  • Hi @mark, I have updated answer, please check the update2 – Vito Liu Apr 20 '21 at 09:51
  • Let me understand the proposal: 1. There will be 2 PR builds - the real one and an auxiliary one. 2. The real one initially does not have any meaningful demands, so it is queued, but there is no agent for it. 3. The auxiliary one checks whether the user has an individual agent, locates the real build instance and modifies its demand to request the user agent or the build server agent. The assumption is that updating the demands dynamically like this would work. Do I understand your idea correctly? – mark Apr 22 '21 at 02:14
  • The real one initially set the "standard" build agent demands, If doese not update the demands, it will run on the "standard" build agent. The auxiliary will update the real on build pipeline demands via the REST API. – Vito Liu Apr 22 '21 at 09:42
  • I do not understand then. If the "real" targets the build agent initially, then what happens when the auxiliary one determines the dev has an individual agent? – mark Apr 22 '21 at 12:59
  • I will have to test it. – mark Apr 23 '21 at 12:53
  • 1
    The testing is going to take time. I will accept for now. If there is a problem, I will let you know. – mark Apr 24 '21 at 18:33
  • I am trying to queue a YAML build on a specific agent and it does not work. Neither from GUI (there is no such option, which did exist for classic builds) nor from REST API - the same command that worked for classic builds no longer works for YAML builds. Our builds are all YAML builds. Please, advise. (I know the question does not mention it, I just did not think it matters) – mark May 19 '21 at 02:41
  • https://stackoverflow.com/questions/67596607/how-to-queue-a-yaml-build-at-the-given-build-agent-in-azure-devops-server-2020-w – mark May 19 '21 at 03:42