How to Use Azure DevOps with GitHub: Simple Integration Guide
To use
Azure DevOps with GitHub, connect your GitHub repository to an Azure DevOps pipeline by authorizing access and selecting your repo. This lets you automate builds and deployments using Azure DevOps while managing code in GitHub.Syntax
Here is the basic syntax to connect GitHub with Azure DevOps pipelines:
- repository: The GitHub repo URL or name.
- serviceConnection: The authorized GitHub connection in Azure DevOps.
- trigger: Defines when the pipeline runs (e.g., on push).
- jobs: The build or deployment steps.
yaml
trigger:
- main
resources:
repositories:
- repository: githubRepo
type: github
name: your-github-username/your-repo-name
endpoint: GitHubServiceConnection
jobs:
- job: Build
steps:
- script: echo "Building from GitHub repo"
displayName: 'Run build script'Example
This example shows a simple Azure DevOps pipeline YAML that triggers on GitHub pushes to the main branch. It uses a GitHub service connection to access the repo and runs a build step.
yaml
trigger:
- main
resources:
repositories:
- repository: githubRepo
type: github
name: example-user/example-repo
endpoint: GitHubConnection
jobs:
- job: Build
steps:
- script: |
echo "Cloning GitHub repo and building..."
git clone https://github.com/example-user/example-repo.git
cd example-repo
echo "Build complete"
displayName: 'Build from GitHub'Output
Cloning GitHub repo and building...
Build complete
Common Pitfalls
Common mistakes when using Azure DevOps with GitHub include:
- Not creating or authorizing a GitHub service connection in Azure DevOps, causing access errors.
- Using incorrect repository names or URLs in the pipeline YAML.
- Forgetting to set triggers properly, so pipelines don’t run on GitHub pushes.
- Not granting Azure DevOps permissions to GitHub repos or missing OAuth consent.
yaml
## Wrong: Missing service connection
resources:
repositories:
- repository: githubRepo
type: github
name: example-user/example-repo
## Right: Include authorized service connection
resources:
repositories:
- repository: githubRepo
type: github
name: example-user/example-repo
endpoint: GitHubConnectionQuick Reference
Tips for smooth Azure DevOps and GitHub integration:
- Create a GitHub service connection in Azure DevOps under Project Settings > Service connections.
- Use the exact GitHub repo name with username and repo (e.g., user/repo).
- Set pipeline triggers to run on GitHub branch pushes.
- Test connection permissions before running pipelines.
Key Takeaways
Authorize a GitHub service connection in Azure DevOps to link your repo securely.
Use correct repo names and set triggers in pipeline YAML to automate builds on GitHub pushes.
Check permissions and OAuth consent to avoid access errors.
Test your pipeline with a simple build step before adding complex tasks.