Lesson 4 of 4 Pipeline Fundamentals

Integrating GitHub Repositories with Azure Pipelines

This lesson explains how to connect the two, and how authentication options differ.

Learning outcomes

After completing this lesson, you will be able to:

  • Compare GitHub App, OAuth and personal access token connections.
  • Describe the setup of a pipeline for a GitHub repository.
  • Require a pipeline as a status check.
  • Explain how fork builds are protected.

Why integrate

Organizations often reach this design while moving code to GitHub without wanting to rewrite pipelines and environments immediately. Azure Pipelines keeps its stages, checks and deployment history, while GitHub becomes the place for code and pull requests. Azure Pipelines also supports specialized needs, such as existing service connections and Azure DevOps Server agents.

Authentication options

Azure Pipelines needs permission to read a repository and report statuses. There are three ways to provide it, and each makes a pipeline run as a different identity.

GitHub App

The Azure Pipelines app, installed from GitHub Marketplace, is the recommended option. The app's identity is used for CI and pull request integration, so nobody's personal account is involved, and it keeps working when an employee leaves. It uses the Checks API, which shows detailed results within a pull request, and allows re-running a failed check from GitHub. Selected repositories can be chosen when installing, and it requires organization owner approval.

OAuth

An OAuth connection authorizes Azure Pipelines to act as a specific GitHub user. It is quick to set up, but it is tied to that person, and statuses appear under their name.

Personal access token

A PAT connection also uses one person's token, with the repo, admin:repo_hook, read:user and user:email scopes for classic tokens. It needs manual rotation, so it is the least attractive option.

GitHub App
IdentityThe app
Checks APIYes
Survives a user leavingYes
MaintenanceLow
Choose when Default choice for GitHub organizations.
OAuth
IdentityA user
Checks APINo; statuses
Survives a user leavingNo
MaintenanceLow
Choose when A quick trial on a personal account.
Personal access token
IdentityA user
Checks APINo; statuses
Survives a user leavingNo
MaintenanceRotation needed
Choose when The app cannot be installed.

The following diagram compares three ways of connecting Azure Pipelines to 80 GitHub repositories.

Connecting Azure Pipelines to 80 GitHub repositories. The Azure Pipelines GitHub App is installed in the organization, so it does not depend on any person, and it uses the Checks API to show detailed test results in pull requests. OAuth and personal access tokens are tied to a user and break when that user leaves.
The scenario is illustrative.
Sort into groups

GitHub App, OAuth or PAT?

Exam skills 3.3.3

Decide which way of connecting Azure Pipelines to GitHub each statement describes.

Log in to try this activity Interactive activities are free with an account.

Setting up a pipeline

  1. Install the app

    A GitHub organization owner installs Azure Pipelines from GitHub Marketplace and selects repositories.

  2. Create a pipeline

    In Azure Pipelines, select New pipeline, choose GitHub, and pick the repository.

  3. Commit the YAML

    The wizard adds azure-pipelines.yml to the GitHub repository, through a commit or pull request.

  4. Check triggers

    CI and pr triggers now work from GitHub events, because the app registers for them.

  5. Require the check

    In GitHub branch protection or a ruleset, make the pipeline a required status check.

Note that the pr keyword does work here. Azure Repos is the exception, and GitHub is not, so a YAML file with both trigger and pr is normal for a GitHub repository.

Put in order

Building a GitHub repository in Azure Pipelines

Exam skills 3.3.3

Arrange the setup of an Azure Pipelines pipeline for a GitHub repository.

Log in to try this activity Interactive activities are free with an account.

Security with forks

Pull requests from forks present a risk, because their code is untrusted, yet the pipeline would run it. By default, Azure Pipelines does not make secrets available to fork builds, and a repository setting controls whether to build forks at all. Fork builds can also be required to wait for a comment from a team member. A self-hosted agent should not run untrusted pull request code, since that code would run on your machine and potentially inside your network.

Other details also matter. Status badges in a README show a pipeline's state. A pipeline can link commits to Azure Boards work items, through the Azure Boards app and AB# syntax. For a monorepo, path filters work the same way as they do for Azure Repos.

True or false

Building pull requests from forks

Exam skills 3.3.3

Check how Azure Pipelines treats untrusted pull requests from forks.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing the connection

A company has moved 80 repositories from Azure Repos to a GitHub organization. Its Azure Pipelines definitions must keep running, and the pipelines must keep working when individuals leave. Developers want to see detailed test results within GitHub pull requests. Which connection should you use?

You should install the Azure Pipelines GitHub App in the organization. It does not depend on a person, and its use of the Checks API shows detailed results in the pull request. OAuth and personal access tokens are both tied to a user, and they would break when that person leaves. Converting all pipelines to GitHub Actions is a larger project than the requirement needs.

Check yourself

Does the pr keyword work for a GitHub repository in Azure Pipelines?

Show answer

Yes. Only Azure Repos ignores it, and that platform uses build validation instead.

Exam Tips

Remember for the exam

  • The Azure Pipelines GitHub App is the recommended connection.
  • OAuth and personal access tokens are tied to a user.
  • The GitHub App reports through the Checks API.
  • The pr keyword works for GitHub repositories.
  • Secrets are withheld from fork builds by default.