DEV Community

Cover image for Trigger Azure Pipelines with GitHub Packages
Davide 'CoderDave' Benvegnù
Davide 'CoderDave' Benvegnù

Posted on • Edited on

Trigger Azure Pipelines with GitHub Packages

Ever wanted to have an Azure Pipelines run starting when a new version of a GitHub Package gets released?

This is exactly what we are going to do today!

Intro

Today I have for you another post in the Azure Pipelines Triggers series, this is the 3rd one and it is about triggering an Azure Pipelines execution when a new GitHub Package version gets released.

For this we will use the Packages type of resource available in the YAML Pipelines.

Video

As usual, if you are a visual learner, or simply prefer to watch and listen instead of reading, here you have the video with the whole explanation and demo, which to be fair is much more complete than this post.

(Link to the video: https://youtu.be/99g1QA_74Z0)

If you rather prefer reading, well... let's just continue :)

Why Packages Triggers?

So, why would you want to do this? I'm glad you've asked.

For example, this can be very useful when your application depends on a package and you want to make sure it still works with the new version of the package. So you start some CI and test work.

In general, there are many scenarios that you can think of where it makes sense triggering a CI or even a CD pipeline when a new version of a package is created.

Enable the Trigger

As I've mention before, to achieve this we can use the YAML Resources. You can in fact consume NuGet and npm GitHub packages as a resource in YAML Pipelines, and enable automated pipeline triggers when a new package version gets released.

This is the YAML snippet we need in our Pipeline:

resources:
  packages:
    - package: myPackageName
      type: NPM
      connection: n3wt0nPAT
      name: HelloNode/hellonodepkg
      trigger: true
Enter fullscreen mode Exit fullscreen mode

Watch the video here for the full explanation of this snippet

This will give our pipelines access to the "hellonodepkg" package of the "HelloNode" repository in GitHub, and call it "myPackageName".

You can specify the type (currently only npm or NuGet), and you can also target a specific version with:

version: 1.2.3
Enter fullscreen mode Exit fullscreen mode

If you don't specify the version, and in the snippet above, then it defaults to latest

Note that the connection must use a Personal Access Token (PAT) for it to work.

And that's basically all you need.

Download the package

Remember that by default packages will not be automatically downloaded into your jobs. To download a package, you have to use the getPackage task:

- getPackage: myPackageName
Enter fullscreen mode Exit fullscreen mode

As you can see, you use the same name you assigned to the package in the resources section.

Watch the video here for the full demo of this in action

Announcement

Before closing, I have an announcement to make, which I'm very excited about. I've finally launched my Patreon page. You can get exclusive content, both posts and videos that are not posted anywhere else. You can influence the content of this blog and my YouTube channel, you can have live chats and Q&A with me. But the coolest part is that you can have a 1:1 consultation with me to talk about anything DevOps, GitHub or Azure DevOps.

Visit my Patreon page to see the options available, just go to patreon.com/CoderDave.

Conclusions

Alright, that's it for today.

Let me know in the comment section below if you think this is useful. And don't forget to check the other posts and videos in the Azure Pipelines Triggers series!

Like, share and follow me 🚀 for more content:

📽 YouTube
Buy me a coffee
💖 Patreon
👕 Merch
👦🏻 Facebook page
🐱‍💻 GitHub
👲🏻 Twitter
👴🏻 LinkedIn
🔉 Podcast

Top comments (0)