CI/CD Azure pipeline example for deployment automation

In the following deployment automation example, the pipeline sets up a CI/CD environment, installs the ch-cli from the Sitecore feed, verifies it works, and then connects it to a Content Hub instance using stored credentials.

CodeDescription
CH_CLI_FEEDPipeline-level variable for the Sitecore NuGet feed URL where ch-cli is published.
CH_CLI_VERSIONPipeline-level variable for CLI version. Leave empty to use the latest version or enter a specific version (for example, 1)
Note

Define CH_ variables shown in the example as variables or secrets within the Azure pipelines themselves. After ch-cli endpoint, use your authenticated instance to execute the commands you need. For additional information about Azure pipelines, see the YAML schema reference.


trigger:
  - main

pool:
  vmImage: ubuntu-latest # or windows-latest

variables:
  CH_CLI_FEED: https://nuget.sitecore.com/resources/v3/index.json
  CH_CLI_VERSION: '' # leave empty for latest, or pin e.g. '1.2.3'

steps:
  - task: UseDotNet@2
    displayName: Install .NET SDK
    inputs:
      packageType: sdk
      version: 8.x

  - script: |
      set -e
      if [ -n "$(CH_CLI_VERSION)" ]; then
        VERSION_ARG="--version $(CH_CLI_VERSION)"
      fi
      dotnet tool install --global --add-source "$(CH_CLI_FEED)" ch-cli $VERSION_ARG
      echo "##vso[task.prependpath]$HOME/.dotnet/tools"
    displayName: Install ch-cli

  - script: ch-cli --version
    displayName: Verify ch-cli

  - script: |
      ch-cli endpoint add \
        --name ci \
        --url "$(CH_URL)" \
        --client-id "$(CH_CLIENT_ID)" \
        --client-secret "$(CH_CLIENT_SECRET)" \
        --username "$(CH_USERNAME)" \
        --password "$(CH_PASSWORD)"

      # ch-cli <your command here>
    displayName: Run ch-cli
    env:
      CH_CLIENT_SECRET: $(CH_CLIENT_SECRET)
      CH_PASSWORD: $(CH_PASSWORD)
If you have suggestions for improving this article, let us know!