Skip to main content

Azure DevOps Pipeline

An Azure DevOps pipeline installs the mass CLI with the mass-cli-install@0 task of the Mass CLI extension, then runs mass commands in script steps.

danger

The extension's other tasks (mass-image-push@0, mass-bundle-publish@0, mass-app-patch@0, mass-app-deploy@0) run commands and flags that mass 2.x no longer has. mass-cli-install@0 installs the latest mass release, so these tasks fail. Use script steps as shown below.

You need:

  • A Massdriver service account in a group that can publish to the bundle's repository and deploy the instance.
  • An Azure DevOps repository with the application code or the bundle.
  • The Mass CLI extension installed in your Azure DevOps organization.

Credentials​

Set these pipeline variables:

NameTypeValue
MASSDRIVER_ORG_IDvariableYour organization ID
MASSDRIVER_API_KEYsecretThe service account secret

Azure Pipelines does not pass secret variables to scripts on its own. Map them in each step's env, as the pipelines below do.

Deploy an application​

Publish the application and add it to the project once by hand. Follow Create an Application, then drag the application from the bundle bar onto the canvas, fill in its fields, and click Save.

This pipeline builds and pushes an image with the built-in Docker@2 task, publishes the bundle, and deploys the instance with the new image tag. acr-connection is a Docker registry service connection to your registry.

azure-pipelines.ymlyaml
trigger:
branches:
include:
- main

pool:
vmImage: 'ubuntu-latest'

stages:
- stage: DeployToMassdriver
jobs:
- job: push_and_deploy
steps:
- checkout: self

- task: Docker@2
displayName: 'Build and push image'
inputs:
command: buildAndPush
containerRegistry: acr-connection
repository: my-app
tags: $(Build.SourceVersion)

- task: mass-cli-install@0
displayName: 'Install Massdriver CLI'

- script: mass bundle publish --bundle-directory ./massdriver
displayName: 'Publish bundle'
env:
MASSDRIVER_ORG_ID: $(MASSDRIVER_ORG_ID)
MASSDRIVER_API_KEY: $(MASSDRIVER_API_KEY)

- script: mass instance deploy inventory-staging-api --patch '.image.tag = "$(Build.SourceVersion)"'
displayName: 'Deploy instance'
env:
MASSDRIVER_ORG_ID: $(MASSDRIVER_ORG_ID)
MASSDRIVER_API_KEY: $(MASSDRIVER_API_KEY)

The argument of mass instance deploy is the instance ID, <project>-<environment>-<component>. It is on the instance's Overview tab.

Instance details panel

The path in --patch is the path to the field in the bundle's params. For this params section of massdriver.yaml, the path to the tag is .image.tag:

massdriver.yamlyaml
params:
required:
- image
properties:
image:
type: object
title: Container Image
required:
- tag
properties:
tag:
title: Image tag
type: string
default: latest

Publish a bundle​

Publish the bundle and add it to a project once by hand. Follow Creating Bundles.

azure-pipelines.ymlyaml
trigger:
branches:
include:
- main

pool:
vmImage: 'ubuntu-latest'

stages:
- stage: PublishToMassdriver
jobs:
- job: publish
steps:
- checkout: self

- task: mass-cli-install@0
displayName: 'Install Massdriver CLI'

- script: mass bundle publish --bundle-directory ./massdriver
displayName: 'Publish bundle'
env:
MASSDRIVER_ORG_ID: $(MASSDRIVER_ORG_ID)
MASSDRIVER_API_KEY: $(MASSDRIVER_API_KEY)

See mass bundle publish for --development, --skip-lint and --fail-warnings.

Both pipelines run on pushes to main. Change the trigger to match your branching.