Azure DevOps

Push packages using Cloudsmith CLI in Azure DevOps pipelines.

1192

Introduction

This document describes the integration of Azure DevOps and Cloudsmith. Azure DevOps is a suite of development tools, services, and features for teams to plan, develop, test, and deliver software. Cloudsmith is a package management and distribution platform. The aim of this integration is to provide a smooth and seamless way to upload your packages in your development pipeline.

Prerequisites

Before getting started, you need to have the following prerequisites:

  • An Azure DevOps account, which can be set up by following the steps in the Azure DevOps documentation.
  • A Cloudsmith account, which can be set up by following the steps in the Cloudsmith documentation.
  • A Cloudsmith Service Account key (recommended) or your personal API key.
    • When using a Personal API key you will have permissions based on your account level so we don't recommend inserting this key into a pipeline if you have access to crucial repositories within your organisation.

Steps for Integration

To integrate Azure DevOps and Cloudsmith, follow these steps:

  1. In your build pipeline create the following three environment variables:
    a. ORG
    b. REPO
    c. CLOUDSMITH_API_KEY

  1. In your azure-pipelines.yml create a section to install the cloudsmith cli:
- script: |
	pip install --upgrade cloudsmith-cli
  displayName: 'Install Cloudsmith CLI'
  1. Once the CLI has been installed we can add an extra step to confirm that everything is working by running cloudsmith whoami -k $(CLOUDSMITH_API_KEY) - this ensures that we can authenticate with Cloudsmith and upload packages:
- script: |
	cloudsmith whoami -k $(CLOUDSMITH_API_KEY)
  displayName: 'Test Cloudsmith Login'
  1. Finally we can upload our package to Cloudsmith, for this example, we will create an empty file called azure.txt, insert Hello World inside, and push it to our repository on Cloudsmith:
- script: |
	touch azure.txt
	echo "Hello World" >> azure.txt
	cloudsmith push raw $(ORG)/$(REPO) azure.txt -k $(CLOUDSMITH_API_KEY)
  displayName: 'Upload a raw file to Cloudsmith'

The final .yaml file should look like this:

# Python package
# Create and upload a raw package to Cloudsmith using Cloudsmith CLI

trigger:
- master

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
   Python37:
      python.version: '3.7'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    pip install --upgrade cloudsmith-cli
  displayName: 'Install Cloudsmith CLI'

- script: |
    cloudsmith whoami -k $(CLOUDSMITH_API_KEY)
  displayName: 'Test Cloudsmith Login'

- script: |
    touch azure.txt
    echo "Hello World" >> azure.txt
    cloudsmith push raw $(ORG)/$(REPO) azure.txt -k $(CLOUDSMITH_API_KEY)
  displayName: 'Upload a raw file to Cloudsmith'

Cloudsmith is the new standard in Package / Artifact Management and Software Distribution

With support for all major package formats, you can trust us to manage your software supply chain.


Start My Free Trial Now
Cookie Declaration (Manage Cookies)