title | description | ms.author | ms.custom | ms.date | monikerRange | author | ms.topic |
---|---|---|---|---|---|---|---|
Use GitHub Actions to push to Azure Artifacts |
Push a NuGet package to Azure Artifacts with a GitHub Actions workflow |
jukullam |
github-actions-azure |
06/06/2023 |
azure-devops |
juliakm |
quickstart |
[!INCLUDE version-eq-azure-devops]
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.
- 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.
[!INCLUDE include]
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.
:::image type="content" source="media/artifacts-nuget-package.png" alt-text="Review new Azure Artifacts feed.":::
If you're not going to continue to use your GitHub workflow, disable the workflow.
[!div class="nextstepaction"] Deploy to Azure using GitHub Actions