Quickstart: Use GitHub Actions to push to Azure Artifacts
Azure DevOps Services
Get started using GitHub Actions and Azure Artifacts together. GitHub Actions help you automate your software development workflows from within GitHub. You can use GitHub Actions to deploy to an Azure Artifacts feed.
Prerequisites
- A GitHub account with a repository. Join GitHub and create a repository.
- An Azure Artifact feed that you'll push your NuGet package to from a GitHub workflow. Get Started with NuGet Packages.
- An Azure DevOps personal access token (PAT) to use with your GitHub action. Create a PAT.
- Your PAT needs to have read, write, and manage Packaging permissions.
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 builds an artifact
GitHub workflows are a series of actions (like tasks in Azure Pipelines). This workflow:
- Sets up a .NET Core CLI environment with the setup-dotnet action.
- Restores dependencies, builds the project and its dependencies into a set of binaries, and runs all unit tests associated with the project.
- Packs the code into a NuGet package with the GitHub Run ID environmental variable included in the version number.
- Publishes the NuGet package to Azure Artifacts.
In your repository on GitHub, create a new YAML file in the
.github/workflows
directory.Copy the following contents into your YAML file. Customize the
AZURE_ARTIFACTS_FEED_URL
,BUILD_CONFIGURATION
, andDOTNET_VERSION
values.- Set
AZURE_ARTIFACTS_FEED_URL
to the registry url for your Azure Artifacts Feed. - Set the
BUILD_CONFIGURATION
. - Set
DOTNET_VERSION
to the version of your project.
name: Push a NuGet package to Azure Artifacts or GitHub Package Registry on: push: branches: - main env: AZURE_ARTIFACTS_FEED_URL: https://pkgs.dev.azure.com/myorg/nuget-artifact/_packaging/Fabrikam_Feed/nuget/v3/index.json BUILD_CONFIGURATION: 'Release' # set this to the appropriate build configuration DOTNET_VERSION: '6.x' jobs: build: runs-on: ubuntu-latest steps: # Checkout the repo - uses: actions/checkout@v2 # Setup .NET Core SDK - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: ${{ env.DOTNET_VERSION }} # Run dotnet build and package - name: dotnet build and test run: | dotnet restore dotnet build --configuration '${{ env.BUILD_CONFIGURATION }}' dotnet test --configuration '${{ env.BUILD_CONFIGURATION }}' az-artifacts-build-and-deploy: needs: build runs-on: ubuntu-latest steps: # Checkout the repo - uses: actions/checkout@v2 # Setup .NET Core SDK - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: ${{ env.DOTNET_VERSION }} source-url: ${{ env.AZURE_ARTIFACTS_FEED_URL }} env: NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }} # Run dotnet build and package - name: dotnet build and publish run: | dotnet restore dotnet build --configuration '${{ env.BUILD_CONFIGURATION }}' dotnet pack -c '${{ env.BUILD_CONFIGURATION }}' --version-suffix $GITHUB_RUN_ID # Publish the package to Azure Artifacts - name: 'dotnet publish' run: dotnet nuget push --api-key AzureArtifacts bin/Release/*.nupkg
- Set
Go to your Azure Artifacts feed to verify that you see the package you pushed.
Clean up resources
If you're not going to continue to use your GitHub workflow, disable the workflow.
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for