azure-devopsazure-pipelines

Can a single machine run two Azure Devops agents from two different agent-pools set in 2 different ADO projects?


Azure DevOps Agent Pool can be set either at ADO-organization-level or ADO-project-level resources. This question pertains to the latter. Consider the following scenario:

  1. ADO Project: Proj1 (e.g.: https://dev.azure.com/single-org/proj1)
  2. Agent Pool in Proj1: Pool-Proj1
  3. Machine M1: Running an agent that belongs to Pool-Proj1

Now, consider another scenario:

  1. ADO Project: Proj2 (e.g.: https://dev.azure.com/single-org/proj2)
  2. Agent Pool in Proj2: Pool-Proj2

Can we install and run the agent process of Pool-Proj2 on Machine M1 along with the one from Pool-proj1? In other words, will there be any impact if M1 is a member of both Pool-Proj1 and Pool-Proj2?

I suppose there shouldn't be any impact since both agents will run as two different OS processes but I can't find any documentation or conversation that advises for or against it.


Solution

  • TL;DR Yes, you can install and configure multiple agents for different projects and/or agent pools on the same VM.

    More details

    A typical startup script for Linux or Windows build agents uses environment variables such as AZP_URL, AZP_POOL and others to configure the build agent.

    Example:

    ./config.sh --unattended \
      --agent "${AZP_AGENT_NAME:-$(hostname)}" \
      --url "${AZP_URL}" \
      --auth "PAT" \
      --token $(cat "${AZP_TOKEN_FILE}") \
      --pool "${AZP_POOL:-Default}" \
      --work "${AZP_WORK:-_work}" \
      --replace \
      --acceptTeeEula & wait $!
    

    Notes:

    Each agent uses a separate folder and have its own startup script. You can hard-code some of the parameters and/or use environment variables, but considering that each agent will have different configuration you need to configure different variables for each agent.

    Consider adding a prefix or suffix to the environment variables used above:

    Agent name Organization URL Agent Pool Token
    Agent project 1 AZP_AGENT_NAME_P1 AZP_URL_P1 AZP_POOL_P1 AZP_TOKEN_P1
    Agent project 2 AZP_AGENT_NAME_P2 AZP_URL_P2 AZP_POOL_P2 AZP_TOKEN_P2

    Startup script for the project 1 build agent can be changed to use the variables with P1 suffix:

    ./config.sh --unattended \
      --agent "${AZP_AGENT_NAME_P1:-$(hostname)}" \
      --url "${AZP_URL_P1}" \
      --auth "PAT" \
      --token $(cat "${AZP_TOKEN_FILE}") \
      --pool "${AZP_POOL_P1:-Default}" \
      --work "${AZP_WORK:-_work}" \
      --replace \
      --acceptTeeEula & wait $!
    

    See the above links for the full startup scripts for both Windows and Linux build agents.