Azure DevOps Docker DotNet Build Agent

This blog post presents how to create and run a DotNet Azure DevOps pipeline as a Docker container. However, there is a slight problem when running VSTest on this container, and the remedy to this problem is explained in this post. Sources related to this container are located in this GitHub repo.

Steps to create, run and test Docker DotNet build agent 

  1. Clone this GitHub repo to the local machine.

  2. Open a Powershell window and navigate to the folder where the cloned project is located.

  3. Execute “docker build -t dockeragent:latest .” to create the Docker image.

  4. Execute “docker run -e AZP_URL=<Azure DevOps instance> -e AZP_TOKEN=<PAT token> -e AZP_AGENT_NAME=mydockeragent -e AZP_POOL=<(optional) pool to register the agent under> dockeragent:latest" to run a container based on the created image. Please remember to replace the placeholders with the information related to your Azure DevOps project.

  5. In a web browser navigate to the Agents tab under the Agent pool you specified in the previous command, and the new agent with the name “mydockeragent” will appear.

Running VSTest on the created Docker DotNet agent

For some reason, VSTest is not available in this Docker Agent (Even though it seems to have an installation of Visual Studio). So any build pipeline with a VSTest task will fail to run on this agent due to the lack of VSTest capability. 


A way around this problem is to use the VSTest installer task in the pipeline, before running the VSTest task to install the needed capability. To do this you can add the following task and the highlighted version update to the VSTest task in your azure-pipelines.yml file.


- task: VisualStudioTestPlatformInstaller@1


- task: VSTest@2

  inputs:

    vsTestVersion: toolsInstaller

    platform: '$(buildPlatform)'

    configuration: '$(buildConfiguration)'


You can find the complete guide on using this Docker container with the template PartsUnlimited project at this link.


Comments

  1. Thanks for the Great Post!
    Prancer is a pre-deployment and post-deployment multi-cloud platform for Infrastructure as Code pipeline and continuous compliance in cloud

    ReplyDelete

Post a Comment

Popular posts from this blog

Running a Docker build agent on Azure Kubernetes Service (AKS)

Building Azure DevOps pipelines with a Docker agent