Trigger an Azure Pipelines run from GitHub Actions
Azure DevOps Services
Get started using GitHub Actions with Azure Pipelines. GitHub Actions help you automate your software development workflows from within GitHub. You can deploy workflows in the same place where you store code and collaborate on pull requests and issues.
If you have both Azure Pipelines and GitHub Actions workflows, you might want to trigger a pipeline run from within a GitHub action. For example, you might have a specific set of pipeline tasks that you want to trigger from your GitHub Actions workflow. You can trigger a pipeline run with the Azure Pipelines action.
Prerequisites
- A working Azure pipeline. Create your first pipeline.
- A GitHub account with a repository. Join GitHub and create a repository.
- An Azure DevOps personal access token (PAT) to use with GitHub Actions. Create a PAT.
Authenticate with Azure Pipelines
Use a personal access token (PAT) to connect your GitHub account to Azure DevOps. You can generate a PAT from within Azure DevOps and then store it as a GitHub secret. Within your GitHub workflow, reference the secret so that your GitHub action can authenticate with your Azure DevOps project.
Open your GitHub repository and go to Settings.
Select Security > Secrets and variables > Actions.
Paste in your PAT and give it the name
AZURE_DEVOPS_TOKEN
.Select Add secret.
Create a GitHub workflow that triggers a pipeline
GitHub workflows are a series of actions (like tasks in Azure Pipelines). Use the Azure Pipelines Action to trigger a pipeline run.
Do the following steps to create a workflow from within GitHub Actions. Then, you can adapt the workflow to meet your needs. The relevant section for connecting to Azure Pipelines is the Azure Pipelines action.
In your repository on GitHub, create a YAML file in the
.github/workflows
directory.Copy the following contents into your YAML file. Customize the
azure-devops-project-url
andazure-pipeline-name
values. Theazure-devops-project-url
shouldn't have a trailing slash.name: CI # Run this workflow every time a commit gets pushed to main or a pull request gets opened against main on: push: branches: - main pull_request: branches: - main jobs: build: name: Call Azure Pipeline runs-on: ubuntu-latest steps: - name: Azure Pipelines Action uses: Azure/pipelines@v1 with: azure-devops-project-url: https://dev.azure.com/organization/project-name azure-pipeline-name: 'My Pipeline' azure-devops-token: ${{ secrets.AZURE_DEVOPS_TOKEN }}
Commit and push your workflow file.
The workflow runs every time you push a commit to main or open a pull request against main. To verify that your action ran, open your GitHub repository and select Actions.
Select the workflow title to see more information about the run. You should see a green check mark for the Azure Pipelines Action. Open the Action to see a direct link to the pipeline run.
Branch considerations
The pipeline your branch runs on depends on whether your pipeline is in the same repo as your GitHub workflow file.
- If the pipeline and the GitHub workflow are in different repositories, the triggered pipeline version in the branch specified by Default branch for manual and scheduled builds runs.
- If the pipeline and the GitHub workflow are in the same repository, the triggered pipeline version in the same branch as the triggering pipeline runs.
To configure the Default branch for manual and scheduled builds setting, see Default branch for manual and scheduled builds setting.
Clean up resources
If you're not going to continue to use your GitHub workflow, disable the workflow.
Next steps
Feedback
Submit and view feedback for