Skip to content

Instantly share code, notes, and snippets.

@csiebler
Last active February 9, 2022 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csiebler/cce8728aad076f1b51abe2cf98b7857d to your computer and use it in GitHub Desktop.
Save csiebler/cce8728aad076f1b51abe2cf98b7857d to your computer and use it in GitHub Desktop.
Adding private Azure DevOps Artifact feeds to Azure Machine Learning

Steps:

  • Create private Feed in Azure DevOps
  • Create Personal Access Token (PAT) in Azure DevOps with Feed Read permission (details)
  • Navigate to the Azure DevOps Artifacts Feed page where you can see the details for the next steps (you'll need feed name, project name, organization name and later also package name): feed terminology
  • Create Build pipeline in Azure DevOps to create package and push to private feed:
trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.8'
    
- script: 'python setup.py sdist'

- script: 'pip install twine'

- task: TwineAuthenticate@1
  inputs:
    artifactFeed: '<PROJECT NAME>/<FEED NAME>'
    
- script: 'twine upload -r <FEED NAME> --config-file $(PYPIRC_PATH) dist/*'
  • Register PAT in the workspace:
from azureml.core import Workspace

ws = Workspace.from_config()
pat_token = input("Enter secret token")
ws.set_connection(name="token-name", 
   category = "PythonFeed",
   target = "https://<ORGANIZATION NAME>.pkgs.visualstudio.com", 
   authType = "PAT", 
   value = pat_token)
  • Create enviroment:
from azureml.core import Environment
from azureml.core.conda_dependencies import CondaDependencies

env = Environment(name="my-env")
cd = CondaDependencies()
cd.add_pip_package("<PACKAGE NAME>")
cd.set_pip_option("--extra-index-url https://<ORGANIZATION NAME>.pkgs.visualstudio.com/<PROJECT NAME>/_packaging/<FEED NAME>/pypi/simple")
env.python.conda_dependencies=cd
  • When working from CLI/with Conda environment YAML files, the use:
name: project_environment
dependencies:
- python=3.6.2
- pip:
  - azureml-defaults
  - <PACKAGE NAME>
  - --extra-index-url https://<ORGANIZATION NAME>.pkgs.visualstudio.com/<PROJECT NAME>/_packaging/<FEED NAME>/pypi/simple
channels:
- anaconda
- conda-forge
@abhishek374
Copy link

abhishek374 commented Apr 28, 2021

@csiebler Why have you used visualstudio.com, want to confirm if the url is still valid with the name being Azure dev ops now ? Also, could you share how to import the package inside the azureml notebook or python file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment