Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
trigger:
branches:
include:
- '*'
schedules:
- cron: "3 12,15,17,22 * * Mon-Fri"
displayName: Daily build of live site
branches:
include:
- master
always: true
variables:
- group: accom sites
# Azure DevOps build pipeline
#
# Triggered on all push to master. Creates two builds & deployes both
# Build 1 - Preview: builds the site including all draft & schedules content to go live
# Build 2 - Live: builds the live site
#
# build on all pushes
trigger:
branches:
include:
- '*'
schedules:
# run @ 10a M-F (1500 UTC)
- cron: "3 12,15,17,22 * * Mon-Fri"
displayName: Daily build of live site
branches:
include:
- master
# always run the schedule, even if no source code changes
always: true
variables:
- group: accom sites
stages:
- stage: Build_Codebase
jobs:
# JOB: Build preview site
- template: build/site-build-job.yml
parameters:
name: build_preview_site
displayName: Preview site (include drafts & future published content)
# always build on pushes to any branch; never on scheduled builds
condition: and(succeeded(), ne(variables['Build.Reason'], 'Schedule'))
hugo_version: 0.57.2
hugo_config_baseUrl: $(PreviewSiteBaseUrl)
hugo_config_flags: '--buildFuture --buildExpired'
site_storage_account: $(PreviewSiteAccount)
site_storage_key: $(PreviewSiteAccessKey)
build_tag: preview-site
# JOB: Build live site
- template: build/site-build-job.yml
parameters:
name: build_live_site
displayName: Live site (exclude drafts & future published content)
# always build on pushes to master
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
hugo_version: 0.57.2
hugo_config_baseUrl: $(LiveSiteBaseUrl)
hugo_config_flags: '--minify'
site_storage_account: $(LiveSiteAccount)
site_storage_key: $(LiveSiteAccessKey)
build_tag: live-site
- stage: Deploy_Codebase
dependsOn: Build_Codebase
jobs:
# JOB: Deploy preview site
- template: build/site-deploy-job.yml
parameters:
name: deploy_preview_site
displayName: Preview site (include drafts & future published content)
condition: and(succeeded(), ne(variables['Build.Reason'], 'Schedule'))
site_storage_account: $(PreviewSiteAccount)
site_storage_key: $(PreviewSiteAccessKey)
build_tag: preview-site
# JOB: Deploy live site
- template: build/site-deploy-job.yml
parameters:
name: deploy_live_site
displayName: Live site (exclude drafts & future published content)
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
site_storage_account: $(LiveSiteAccount)
site_storage_key: $(LiveSiteAccessKey)
build_tag: live-site
# 3. Executes Hugo to build site with specified arguments
- script: hugo --baseUrl '${{ parameters.hugo_config_baseUrl }}' ${{ parameters.hugo_config_flags }}
displayName: Build site with Hugo (include future & expired content)
# 5. Copy all relevant built files => staging folder (workaround for archiving)
- task: CopyFiles@2
displayName: Copy Hugo built site files to staging folder "deploy"
inputs:
Contents: |
config.yml
public/**
resources/**
static/**
themes/**
TargetFolder: deploy
# 6. Archive (e.g. zip) all built files
- task: ArchiveFiles@2
displayName: Archive built site files
inputs:
rootFolderOrFile: ./deploy
includeRootFolder: false
archiveType: zip
archiveFile: $(Pipeline.Workspace)/hugo-build.zip
replaceExistingArchive: true
# 1. Downloads specified version of Hugo executable
- script: wget https://github.com/gohugoio/hugo/releases/download/v${{ parameters.hugo_version }}
/hugo_${{ parameters.hugo_version }}_Linux-64bit.deb
-O '$(Pipeline.Workspace)/hugo_${{ parameters.hugo_version }}_Linux-64bit.deb'
displayName: Download Hugo v${{ parameters.hugo_version }} Linux x64
# 2. Installs Hugo executable
- script: sudo dpkg -i $(Pipeline.Workspace)/hugo*.deb
displayName: Install Hugo
# 4. Executes Hugo `deploy` command to log all files that would be
# added/updated/deleted to the Azure site
- script: hugo deploy --maxDeletes -1 --dryRun
displayName: Log files added/updated/deleted in site build
env:
AZURE_STORAGE_ACCOUNT: ${{ parameters.site_storage_account }}
AZURE_STORAGE_KEY: ${{ parameters.site_storage_key }}
# 7. Publish Hugo installer for later stages
- publish: $(Pipeline.Workspace)/hugo_${{ parameters.hugo_version }}_Linux-64bit.deb
artifact: hugo-installer
# 8. Publish built site codebase for later stages
- publish: $(Pipeline.Workspace)/hugo-build.zip
artifact: build-${{ parameters.build_tag }}
# 1. Downloads Hugo executable from published artifacts
- download: current
artifact: hugo-installer
# 2. Downloads built site codebase from published artifacts
- download: current
artifact: build-${{ parameters.build_tag }}
# 4. Extracts the zip'd site codebase
- task: ExtractFiles@1
displayName: 'Extract files '
inputs:
archiveFilePatterns: '$(Pipeline.Workspace)/build-${{ parameters.build_tag }}/hugo-build.zip'
destinationFolder: '$(Pipeline.Workspace)/build-${{ parameters.build_tag }}/deploy'
cleanDestinationFolder: false
# 5. Executes Hugo `deploy` command to publish all files to Azure Storage blob
- script: 'hugo deploy --maxDeletes -1'
workingDirectory: '$(Pipeline.Workspace)/build-${{ parameters.build_tag }}/deploy'
displayName: 'Deploy build to site'
env:
AZURE_STORAGE_ACCOUNT: ${{ parameters.site_storage_account }}
AZURE_STORAGE_KEY: ${{ parameters.site_storage_key }}
# 3. Installs Hugo executable
- script: 'sudo dpkg -i hugo*.deb'
workingDirectory: '$(Pipeline.Workspace)/hugo-installer'
displayName: 'Install Hugo'
# Azure DevOps Build Pipeline
#
# This job template is used in the build stage. It does the following:
# 1. Downloads specified version of Hugo executable
# 2. Installs Hugo executable
# 3. Executes Hugo to build site with specified arguments
# 4. Executes Hugo `deploy` command to log all files that would be
# added/updated/deleted to the Azure site
# 5. Copy all relevant built files => staging folder (workaround for archiving)
# 6. Archive (e.g. zip) all built files
# 7. Publish Hugo installer for later stages
# 8. Publish built site codebase for later stages
parameters:
# unique name of the job
name: ''
# friendly name of the job
displayName: ''
# condition when the job should run
condition: {}
# Hugo version to use in stage; e.g. #.#.# (do not include 'v' prefix)
hugo_version: ''
# Hugo value for argument --baseUrl
hugo_config_baseUrl: ''
# Hugo argument flags to include
hugo_config_flags: ''
# Azure Storage Account name & access key where site is deployed
site_storage_account: ''
site_storage_key: ''
# Unique tag for site type
build_tag: ''
jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
pool:
vmImage: ubuntu-latest
condition: ${{ parameters.condition }}
steps:
# 1. Downloads specified version of Hugo executable
- script: wget https://github.com/gohugoio/hugo/releases/download/v${{ parameters.hugo_version }}
/hugo_${{ parameters.hugo_version }}_Linux-64bit.deb
-O '$(Pipeline.Workspace)/hugo_${{ parameters.hugo_version }}_Linux-64bit.deb'
displayName: Download Hugo v${{ parameters.hugo_version }} Linux x64
# 2. Installs Hugo executable
- script: sudo dpkg -i $(Pipeline.Workspace)/hugo*.deb
displayName: Install Hugo
# 3. Executes Hugo to build site with specified arguments
- script: hugo --baseUrl '${{ parameters.hugo_config_baseUrl }}' ${{ parameters.hugo_config_flags }}
displayName: Build site with Hugo (include future & expired content)
# 4. Executes Hugo `deploy` command to log all files that would be
# added/updated/deleted to the Azure site
- script: hugo deploy --maxDeletes -1 --dryRun
displayName: Log files added/updated/deleted in site build
env:
AZURE_STORAGE_ACCOUNT: ${{ parameters.site_storage_account }}
AZURE_STORAGE_KEY: ${{ parameters.site_storage_key }}
# 5. Copy all relevant built files => staging folder (workaround for archiving)
- task: CopyFiles@2
displayName: Copy Hugo built site files to staging folder "deploy"
inputs:
Contents: |
config.yml
public/**
resources/**
static/**
themes/**
TargetFolder: deploy
# 6. Archive (e.g. zip) all built files
- task: ArchiveFiles@2
displayName: Archive built site files
inputs:
rootFolderOrFile: ./deploy
includeRootFolder: false
archiveType: zip
archiveFile: $(Pipeline.Workspace)/hugo-build.zip
replaceExistingArchive: true
# 7. Publish Hugo installer for later stages
- publish: $(Pipeline.Workspace)/hugo_${{ parameters.hugo_version }}_Linux-64bit.deb
artifact: hugo-installer
# 8. Publish built site codebase for later stages
- publish: $(Pipeline.Workspace)/hugo-build.zip
artifact: build-${{ parameters.build_tag }}
# Azure DevOps Build Pipeline
#
# This job template is used in the deploy stage. It does the following:
# 1. Downloads Hugo executable from published artifacts
# 2. Downloads built site codebase from published artifacts
# 3. Installs Hugo executable
# 4. Extracts the zip'd site codebase
# 5. Executes Hugo `deploy` command to publish all files to Azure Storage blob
parameters:
# unique name of the job
name: ''
# friendly name of the job
displayName: ''
# condition when the job should run
condition: {}
# Azure Storage Account name & access key where site is deployed
site_storage_account: ''
site_storage_key: ''
# Unique tag for site type
build_tag: ''
jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
pool:
vmImage: ubuntu-latest
condition: ${{ parameters.condition }}
steps:
# 1. Downloads Hugo executable from published artifacts
- download: current
artifact: hugo-installer
# 2. Downloads built site codebase from published artifacts
- download: current
artifact: build-${{ parameters.build_tag }}
# 3. Installs Hugo executable
- script: 'sudo dpkg -i hugo*.deb'
workingDirectory: '$(Pipeline.Workspace)/hugo-installer'
displayName: 'Install Hugo'
# 4. Extracts the zip'd site codebase
- task: ExtractFiles@1
displayName: 'Extract files '
inputs:
archiveFilePatterns: '$(Pipeline.Workspace)/build-${{ parameters.build_tag }}/hugo-build.zip'
destinationFolder: '$(Pipeline.Workspace)/build-${{ parameters.build_tag }}/deploy'
cleanDestinationFolder: false
# 5. Executes Hugo `deploy` command to publish all files to Azure Storage blob
- script: 'hugo deploy --maxDeletes -1'
workingDirectory: '$(Pipeline.Workspace)/build-${{ parameters.build_tag }}/deploy'
displayName: 'Deploy build to site'
env:
AZURE_STORAGE_ACCOUNT: ${{ parameters.site_storage_account }}
AZURE_STORAGE_KEY: ${{ parameters.site_storage_key }}
stages:
# build stage: build site codebase to use for deployment
- stage: Build_Codebase
jobs:
- template: build/site-build-job.yml
parameters:
name: build_live_site
displayName: Live site (exclude drafts & future published content)
# always build on pushes to master
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
hugo_version: 0.57.2
hugo_config_baseUrl: $(LiveSiteBaseUrl)
hugo_config_flags: '--minify'
site_storage_account: $(LiveSiteAccount)
site_storage_key: $(LiveSiteAccessKey)
build_tag: live-site
- stage: Deploy_Codebase
dependsOn: Build_Codebase
jobs:
- template: build/site-deploy-job.yml
parameters:
name: deploy_live_site
displayName: Live site (exclude drafts & future published content)
# always deploy on pushes to master
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
site_storage_account: $(LiveSiteAccount)
site_storage_key: $(LiveSiteAccessKey)
build_tag: live-site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.