NashTech Insights

How to store artifacts into Azure artifacts using ADO pipeline

Harshit Gupta
Harshit Gupta
Table of Contents
coding script

What is Azure Artifacts

Azure Artifacts provides developers with efficient code storage and package management in one place. Using Azure Artifacts, we store packages in their feeds and distribute them to the same team members across organizations. Developers can use newsfeed and public log packages like NuGet.org or npmjs.com. It supports different package types like NuGet, npm, Python, Maven, etc.

In this blog i am using a basic python project.Firstly we build the python project and push into the Azure ADO using twine python package manager.

Prerequisite:

  • Azure Account.
  • Latest python version.
  • Azure DevOps.
  • Azure ADO Agent.
Steps for Build and Store Artifacts:

Step 1 : First create the package of the python code , for that we have to create pyproject.toml file and add the configuration on that file.

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "SimplepythonProject"
version = "0.0.1"
authors = [
  { name="Harshit", email="harshit@example.com" },
]

In the above code snippet there the project section we defined the package name that is uploaded into the ADO its version and authors.

Step 2: Create the feed on the Azure DevOps and add the permission on that as shown in the below image.

Step 3 : In the pipeline configuration we need to install twine python package.

Firstly we need to install the pip and install the python

- script: |
      python3 -m pip install --upgrade build
      pip install twine
      python3 -m build
  displayName: 'Install dependencies'     python -m twine upload -r "pypitest" --config-file $(PYPIRC_PATH) dist/*.whl

Step 4 : Upload the package into the ADO Artifacts using the twine upload command.

Here is the ADO pipeline for the python project.

Here in the pipeline you can see firstly we install the twine package.

Add the task for twine authentication there give the feed name that are created in the ADO portal. Then after add the script for upload the artifact on the ADO.

trigger: 
- "enter your branch name here"

pool: "Enter your pool name here"
steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.8'
  displayName: 'Use Python 3.8'

- script: |
      python3 -m pip install --upgrade build
      pip install twine
      python3 -m build
  displayName: 'Install dependencies'

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: 'Enter feed name here'
  displayName: 'Authenticate the Twine'   
    
- script: |
      twine upload -r "'Enter feed name here'" --config-file $(PYPIRC_PATH) dist/* --verbose
  displayName: 'Publish artifacts into ADO'

Here in the above image you can see the artifact stored in the ADO.

So these are the steps of store artifacts into ADO Artifacts you can store package and retrieve from here according to their needed.

References:

https://packaging.python.org/en/latest/tutorials/packaging-projects/

https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/pypi?view=azure-devops&tabs=yaml

Harshit Gupta

Harshit Gupta

I Harshit Gupta working as a Software Consultant at knoldus Inc|Part of Nashtech have 2.5 years of experience in DevOps. I am always eager to learn new technology and helping to others

Suggested Article

%d