Use Self-hosted Agent

Here we will learn how we can use a Self-hosted agent in Azure Pipeline created in the last module. We will create a simple Azure Pipeline in which we select our Self-hosted agent. We will get the source code from a remote repository (GitHub). This is going to be a simple Azure Pipeline project.


Step 1. Skipping the Azure Repo.

Here we will skip the Azure Repo part as we will discuss in the next module.


Step 2. Create Azure Pipeline

Note: this step has GitHub authorization step, only to learn how to get the code from other VCS. We will not be going to use the source present in GitHub. This Module is only to learn how to use a Self-hosted agent in the Azure pipeline.

Skipping directly to Azure Pipeline.

✔ Click on Create Pipeline button.

Select Pipeline Editor, you have two options to create Azure Pipeline, using YAML and using the Classic editor (GUI-based pipeline editor).

Select your repository, you can get the code from different VCS for the pipeline. We will choose GitHub as we are getting code from a remote repository.



✔ Click on Authorize using the OAuth button to authorize the connection between GitHub and Azure DevOps.


github ad authorization


✔ Click on Authorize AzurePipelines and confirm with GitHub password on next page and authorization is complete.

✔ Next, select the repository and branch of GitHub and click Continue.

✔ Choose Empty Job at the top.


Step 3. Setting up Azure Pipeline to Work with Self-hosted Agent

Now, we will set up the Build Pipeline.

build pipeline


✔ Here in Pipeline, set up as follows:

    ✔ Name: Give an appropriate name for the build pipeline.

    ✔ Agent pool: Choose the pool you have created. (Make sure the Agent in the Agent pool is online).


Step 4. Adding a job for the agent.

We will add a simple PowerShell task and run a command on the agent.

✔ Click on the plus (+) icon to add a task.

✔ Search for PowerShell and add that in the Agent Job.

✔ Configure PowerShell task as follows:

    ✔ Display name: Name of the Job.

    ✔ Type: we can provide the path of a PowerShell script in the File path option or write the script directly here in the Inline option. We choose Inline it will give an example script that we can use here or we can run a command pwd that will give the current path as output.

    ✔ Leave other as default.


✔ Save the configuration by clicking the Save option from the drop-down at the top.


Step 5. Run the Build Pipeline.

✔ Click on the Queue button at the top.

✔ Click on Run to run the build on a self-hosted agent.


✔ On the next page, click on Agent Job 1 and see the logs of the build.

✔ After some time, the build will complete successfully.


successful build



We have learned how to create a simple Azure Pipeline and use the self-hosted agent created earlier in the previous module. And get the code from 3rds party VCS such as GitHub.