Skip to content

Instantly share code, notes, and snippets.

@markf3lton
Last active June 3, 2024 04:23
Show Gist options
  • Save markf3lton/ce5d65304c9b6c059560edabfaf0a2a1 to your computer and use it in GitHub Desktop.
Save markf3lton/ce5d65304c9b6c059560edabfaf0a2a1 to your computer and use it in GitHub Desktop.

Acquia BLT in Azure DevOps Pipelines

This guide will get you started with Acquia BLT and AzDo (Azure DevOps).

I wrote a guide for running BLT on Windows that will complement this tutorial.

I also wrote a Getting Started with BLT guide.

Set up your Azure Repo

The industry standard is Github but many folks use Bitbucket, Gitlab, or even Azure DevOps. My guide for Github is here.

Create a BLT project and push it to your Azure Repo.

You will want to set your origin to Azure and also set acquia as a remote:

git remote add acquia [email protected]:woburn.git

Set up your SSH key as a Secure File

I assume you have created a public/private key pair using the ssh-keygen instructions on this page: https://docs.acquia.com/acquia-cloud/manage/ssh/generate/

Under Pipelines > Library, upload the private key as a secure file.

First I make a copy of it, I am using WSL/Ubuntu on Windows 10 so I can use standard bash commands:

cp ~/.ssh/id_rsa /mnt/c/Users/mfelton001/Documents/private-key.txt

You will need to toggle the option to "Authorize for use in all Pipelines".

Also on the Security settings. Administrators are fine, but the group members who are marked as "Reader" should be changed to "User" so they can use these secure files...

Set up your Pipeline

Click the button to add a new Pipeline, select the Azure Repo, Choose PHP (the first option)

Click on line 27, search widgets for SSH, choose the option "Install SSH Key"

You will need to have known_hosts entry for your Acquia SVN repo, and of course your passphrase.

Save your azure-pipelines.yml file.

You can read more about CI solutions on Acquia Docs: https://docs.acquia.com/blt/tech-architect/ci/

azure-pipelines.yml

The file felow is a good way to get familiar with Azure Pipelines running some BLT commands.

# PHP
# Test and package your PHP project.
# Add steps that run tests, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/php

trigger:
- master

pool:
  vmImage: 'ubuntu-16.04'
  COMPOSER_BIN: $(Build.Repository.LocalPath)/vendor/bin
  BLT_DIR: $(Build.Repository.LocalPath)/vendor/acquia/blt
  LOCAL_BLT_DIR: $(Build.Repository.LocalPath)/blt/src

variables:
  phpVersion: 7.2

steps:
- script: |
    sudo update-alternatives --set php /usr/bin/php$(phpVersion)
    sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
    sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
    sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
    php -version
  displayName: 'Use PHP version $(phpVersion)'


- task: CmdLine@2
  inputs:
    script: |
      echo ' '
      echo Write your commands here!!
      mysql --version
      echo ' '
  displayName: 'Testing some commands'


- script: composer install --no-interaction --prefer-dist
  displayName: 'composer install'


- task: InstallSSHKey@0
  inputs:
    knownHostsEntry: 'svn-8018.devcloud.hosting.acquia.com,54.54.86.113 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZLDJOkdLKbvf2hEclleJJ2zOJjr9omVSfAFmJPe/HqDJTinSEihJuyYkORzOCBm789mQYcVPPodEwDEP20pW38f2hz+fYqK4hB2cDV/epUv4GL7ebJfto8UUnGQTWSRUHf2wVyYQwMGV9XA6MsiHYLd3xgvL4RZ47TbsfukL0mzlsc0lq3nPrzi0WxKS+614Eqg2mBpSLNGOUOGbz64h8bnpa/5ww2GCscymYGWcM403x2dDEliOplFNlKztgs+of5Zf9AT8Eh1O20jiBz85dUL1eintKSOau/jzrz5IP+SkpM9u+80H1hUe39w4t5/UdWHTYtlRqjflXjt/A8iZj'
    sshPublicKey: 'ssh-rsa AAABBgmw=='
    sshPassphrase: '12345'
    sshKeySecureFile: 'id_rsa'
  displayName: 'Install the SSH key that we need for the external git repo'


- task: CmdLine@2
  inputs:
    script: |
      echo ' '
      cat ~/.ssh/known_hosts | awk '{print $1}'
      echo ' '
      # Verify that BLT was installed
      vendor/bin/blt
      echo ' '
  displayName: 'Preflight before continuing to the next step'


- task: CmdLine@2
  inputs:
    script: |
      set -ev

      # Set the git configuration
      git config --global user.name "Azure-CI"
      git config --global user.email "[email protected]"
      
      # Create a MySQL database for drupal to use
      mysql -u root -proot -e "CREATE DATABASE drupal; CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'drupal'; GRANT ALL ON drupal.* TO 'drupal'@'localhost';"
      
      set +ev
  displayName: 'Set up the environment for Drupal'


- task: CmdLine@2
  inputs:
    script: |
      set -ev

      vendor/bin/blt validate:all --no-interaction
      # Run "blt setup"
      vendor/bin/blt setup --no-interaction --ansi --verbose

      # Run "blt doctor"
      # vendor/bin/blt doctor

      set +v
  displayName: 'Install Drupal!'


- task: CmdLine@2
  inputs:
    script: |
      set -ev
      
      # Run blt artifact:deploy
      vendor/bin/blt artifact:deploy --commit-msg "Automated commit by Azure Devops CI for Build" --tag "azure-build-${BUILD_BUILDID}" --ignore-dirty --no-interaction --verbose
      
      set +v
  displayName: 'Build,  then tag, then deploy the build artifact!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment