Azure DevOps
Push packages using Cloudsmith CLI in Azure DevOps pipelines.
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:
- In your build pipeline create the following three environment variables:
a. ORG
b. REPO
c. CLOUDSMITH_API_KEY
- In your
azure-pipelines.yml
create a section to install the cloudsmith cli:
- script: |
pip install --upgrade cloudsmith-cli
displayName: 'Install Cloudsmith CLI'
- 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'
- Finally we can upload our package to Cloudsmith, for this example, we will create an empty file called
azure.txt
, insertHello 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'
Updated about 1 year ago