Document

SUBSCRIBE TO GET FULL ACCESS TO THE E-BOOKS FOR FREE 🎁SUBSCRIBE NOW

Professional Dropdown with Icon

SUBSCRIBE NOW TO GET FREE ACCESS TO EBOOKS

Azure DevOps - Self-hosted agents

 Self-hosted agents

An agent that you set up and manage on your own to run jobs is a self-hosted agent. You can use self-hosted agents in Azure Pipelines or Azure DevOps Server, formerly named Team Foundation Server (TFS). Self-hosted agents give you more control to install dependent software needed for your builds and deployments. Also, machine-level caches and configurations persist from run to run, which can boost speed.

You can install the agent on different OS. There are different agents on different OS

  • macOS agent
  • Linux agent (x64, ARM, ARM64, RHEL6)
  • Windows agent (x64, x86)
  • Docker agent

Self-hosted Windows agents

Prerequisites

  • Windows 7 SP1 ESU, 8.1, 10, or 11 (if using a client OS)
  • Windows 2012 or higher (if using a server OS)
  • PowerShell 3.0 or higher
  • .NET Framework 4.6.2 or higher 

Authenticate with a personal access token (PAT)

  1. Sign in with the user account you plan to use in your Azure DevOps organization (https://dev.azure.com/{your_organization}).
  1. From your home page, open your user settings, and then select Personal access tokens.

    Go to your security details.

  2. Create a personal access token.

    Create a personal access token.

  1. For the scope select Agent Pools (read, manage) and make sure all the other boxes are cleared. If it’s a deployment group agent, for the scope select Deployment group (read, manage) and make sure all the other boxes are cleared.

    Select Show all scopes at the bottom of the Create a new personal access token window window to see the complete list of scopes.

  2. Copy the token. You’ll use this token when you configure the agent.

Confirm the user has permission

Make sure the user account that you’re going to use has permission to register the agent.

Is the user an Azure DevOps organization owner or TFS or Azure DevOps Server administrator? Stop here, you have permission.

Otherwise:

  1. Open a browser and navigate to the Agent pools tab for your Azure Pipelines organization or Azure DevOps Server or TFS server:

    1. Choose Azure DevOpsOrganization settings.

      Choose Organization settings.

    2. Choose Agent pools.

      Choose Agent pools tab.

  2. Azure pipeline Agent pool is used for MS-hosted agents and Default is used for self-hosted agents.

  3. Click on Default and then click on the New Agent button.

  4. It will open the set of instructions to Download Agent and install agent so follow those instructions and install the agent on a windows machine.

  5. Server URL:- Enter URL for Organization like https://dev.azure.com/myrepo321

  6. PAT:- Personal Access Token which is created in user profile.

  7. Agen Pool:- Default

  8. Agent Name:- provide any valid name or press enter for default name

  9. Work folder:- Press Enter or you can provide any folder where you want to keep the artifacts.

  10. Enter run agent as a service:- Press Enter for if you want to run as a windows service then you can choose Y.

  11. Enter Configure Autologon and Run agent on Startup: Press Enter for N and Y for yes.

  12. Under this folder run the command .\run.cmd

  13. Check Agent pool –> Default Pool and you will find the Agent is created and has Online Status.

  14. Create a new pipeline or Edit any existing pipeline by providing the below code. In this example, RAMAN-SHARMA is the agent which is created in the Default Agent pool. After writing the code Run the pipeline (It will ask the permission to allow the user to execute the pipeline, so provide the permission by clicking on the Permit button)

    # Build and test ASP.NET Core projects targeting the full .NET Framework.
    # Add steps that publish symbols, save build artifacts, and more:
    # https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

    trigger:
    – master
    #Define the Agent pool configuration here. RAMAN-SHARMA is agent Name
    pool:
      name: ‘Default’
      vmImage: ‘RAMAN-SHARMA’

    variables:
      solution: ‘**/*.sln’
      buildPlatform: ‘Any CPU’
      buildConfiguration: ‘Release’

    steps:
    – task: NuGetToolInstaller@1

    – task: NuGetCommand@2
      inputs:
        restoreSolution: ‘$(solution)’

    – task: VSBuild@1
      inputs:
        solution: ‘$(solution)’
        msbuildArgs: ‘/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation=”$(build.artifactStagingDirectory)\WebApp.zip” /p:DeployIisAppPath=”Default Web Site”‘
        platform: ‘$(buildPlatform)’
        configuration: ‘$(buildConfiguration)’
  15. Once the Job is executed successfully you will find the artifacts in the configured directory.

Share your love

Leave a Reply

Your email address will not be published. Required fields are marked *