Publish and download Universal Packages with ADO Pipelines


Hello again ๐๐ป ! So today we will learn about how can we publish and download artefacts from Azure artefacts using the ADO pipeline.
Since we are going to use the ADO pipeline so you must have created at least a free account in azure devops. To get started with ADO Pipelines you can follow this blog here ๐
Introduction to Azure Artifact
Azure Artifacts is a package management service in Microsoft Azure.
It supports multiple package types like NuGet, npm, Maven, Python, Universal Pacakge etc.
Enables versioning, dependency management, and access control.
Integrates with Azure DevOps tools for automation.
Acts as a package proxy, caching external packages.
Provides granular access control, allowing you to manage who can publish and consume packages.
To explore more about azure artifact you can refer to documentation https://learn.microsoft.com/en-us/azure/devops/artifacts/?view=azure-devops
โ Prerequisites :
๐ You need to have an Azure Devops organisation
and projects
If you dont have already refer to this blog https://saumyapandey.hashnode.dev/automating-terraform-deployments-with-azure-devops-pipeline#heading-create-free-account-for-ado
๐ Create an azure Feed. To create a feed :
Got to your project . For me its Test-Project
In the left side Panel click on
Artifacts
After that click on Create Feed button and provide the name of your feed and leave the rest of the setting as it is and click on Create .
Your feed is ready and you can see it near the drop-down at the top. You can also select any feed from here in case you have multiple feeds inside a single project.
Publish Pipeline for Universal Package
Universal Package is a type of package format that provides a flexible and extensible way to store and distribute software components. It can hold any type of file or artifact, making it suitable for packaging a wide range of assets such as executables, binaries, scripts, documentation, and configuration files.
Hence we will try to store terraform configuration files here with different versions.
# Build pipeline
name: "Terraform Build Pipeline for acr"
trigger:
- main
pr: none
parameters:
- name: ArtifactName
displayName: 'Artifact Name'
default: "acr"
type: string
- name: ArtifactVersion
displayName: 'Artifact Version'
default: 1.0.0
pool:
vmImage: ubuntu-latest
steps:
- task: UniversalPackages@0
inputs:
command: 'publish'
publishDirectory: '$(Build.SourcesDirectory)'
feedsToUsePublish: 'internal'
vstsFeedPublish: 'saumyabhushan666/universal-package-terraform'
vstsFeedPackagePublish: '${{ parameters.ModuleName }}'
versionOption: 'custom'
versionPublish: '${{ parameters.ModuleName }}'
packagePublishDescription: 'acr terraform package'
verbosity: 'Error'
You can change the arguments according to your need. Here is a small brief of all the arguments
publishDirectory: Specify the location of the files that you want to publish. It represents the directory path containing the package files or artifacts.
vstsFeedPublish: Specify the project and feed name where you want to publish the package. If you are using an organization-scoped feed, you only need to provide the feed name.
vstsFeedPackagePublish: Specifies the name of the package to publish. The package name must be in lowercase and can only include letters, numbers, and dashes.
versionOption: Allows you to select a versioning strategy for the package. Options include
"major," "minor," "patch," or "custom."
This determines how the package version is incremented or specified.versionPublish: This argument is used when the
"custom"
versioning strategy is selected. It allows you to provide aspecific version
for the package instead of using the default versioning strategy.packagePublishDescription: Describes the package content. It is an optional field that allows you to add information about the package's contents, purpose, or any relevant details.
Download the package and run it through the ADO pipeline
name: deploy-${{ parameters.artifact }}-${{ parameters.version }}
trigger: none
parameters:
- name: subscription
displayName: "Subscription ID"
type: string
- name: artifact
displayName: "Artifact name ( aks | acr | ... )"
type: string
- name: version
displayName: "Artifact version ( major.minor.patch )"
type: string
- name: view
displayName: "ADO Artifacts feed view ( Local | Prerelease | Release )"
default: "Local"
type: string
stages:
- stage: deploy
jobs:
- job: deploy
timeoutInMinutes: 0
steps:
- task: AzureKeyVault@2
displayName: Get common secrets from key-valut
inputs:
azureSubscription: "test"
KeyVaultName: "test-kv"
SecretsFilter: "appid,appsecret,TenantId"
RunAsPreJob: false
- task: DownloadPackage@1
inputs:
packageType: "upack"
feed: 'saumyabhushan666/universal-package-terraform'
view: "${{ parameters.view }}"
definition: "${{ parameters.artifact }}"
version: "${{ parameters.version }}"
downloadPath: "$(System.DefaultWorkingDirectory)"
- script: |
(echo azure_tenant_id = \"$(TenantId)\"
echo azure_client_id = \"$(appid)\"
echo azure_client_secret = \"$(appsecret)\"
echo azure_subscription_id = "\"${{ parameters.subscription }}\""
) >> module/terraform.auto.tfvars
displayName: "Create Azure Credentials file "
- task: TerraformInstaller@0
displayName: "Terraform install v1.1.4"
inputs:
terraformVersion: "1.1.4"
- script: |
terraform init -upgrade"
displayName: "Terraform Init"
- script: |
terraform fmt
displayName: "Terraform Format"
- script: |
terraform validate
displayName: "Terraform Validate"
- script: |
terraform apply -auto-approve
displayName: "Terraform Apply"
This is a basic yaml script to download the Terraform universal package and just run it in the ADO pipeline to create your infrastructure.
This is the main script to download the package which has been included in the above yaml script. :
- task: DownloadPackage@1
inputs:
packageType: "upack"
feed: 'saumyabhushan666/universal-package-terraform'
view: "${{ parameters.view }}"
definition: "${{ parameters.artifact }}"
version: "${{ parameters.version }}"
downloadPath: "$(System.DefaultWorkingDirectory)"
For more details on this, you can refer to the documentation here https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/universal-packages-v0?view=azure-pipelines&source=recommendations
That's the end of this blog !! ๐ If you want me to write more blogs related to the ADO pipeline or if you are facing any issues ๐ฉ๐ปโ๐ป while setting up the pipeline you can comment I will get back to you ๐ค.
You can follow me on
Twitter: https://twitter.com/saumya_bhushan
Linkedin: https://www.linkedin.com/in/saumya-pandey-076572166/
GitHub: https://github.com/SaumyaBhushan
Hashnode: Saumya Pandey
Subscribe to my newsletter
Read articles from DevOps Talks directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

DevOps Talks
DevOps Talks
Hey there, I'm the DevOps wizard with a passion for automating everything in sight. When I'm not knee-deep in code, I love to explore the latest tech trends and listen to my favorite tunes. With my keen attention to detail and problem-solving skills, I'm the go-to person for any infrastructure challenge or automation.