Skip to content

Instantly share code, notes, and snippets.

@sfabijanski
Last active April 5, 2023 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfabijanski/0faeff9eaa274af48a637fb3d4edf6f8 to your computer and use it in GitHub Desktop.
Save sfabijanski/0faeff9eaa274af48a637fb3d4edf6f8 to your computer and use it in GitHub Desktop.
ADO Build Pipeline Template

ADO Build Pipeline Template

A template build pipeline that demonstrates a few possible choices when building a pipeline

  • naming the build with the name keyword
  • triggering on various branches
  • triggering only when the files updated are in a particular folder
  • dynamic variable assignment based off of the branch committed to
    • could also be handled with variable groups (not used here)
  • pulling variable values from a key vault
  • use the env keyword on a task to populate process.env variables
  • publishing artifacts to a named drop
  • publishing a Single Page Application to an Windows-based Azure App Service
name: 'myapp-Web-App:_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)'
trigger:
branches:
include:
- development
- main
- feat-*
- fix-*
paths:
include:
- src
variables:
${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
appSvc: 'app-dept-myapp-org-prod'
env: 'production'
serviceConnection: 'conn-dept-myapp-prod'
keyVault: 'kv-dept-myapp-prod'
stappSlot: ''
${{ if eq(variables['Build.SourceBranchName'], 'staging') }}:
appSvc: 'app-dept-myapp-org-qa'
env: 'staging'
serviceConnection: 'conn-dept-myapp-qa'
keyVault: 'kv-myapp-qa'
stappSlot: ''
${{ if eq(variables['Build.SourceBranchName'], 'development') }}:
appSvc: 'app-dept-myapp-org-dev'
env: 'development'
serviceConnection: 'conn-dept-myapp-dev'
keyVault: 'kv-myapp-dev'
stappSlot: ''
${{ if contains(variables['Build.SourceBranchName'], 'fix') }}:
appSvc: 'app-dept-myapp-org-dev'
env: 'development'
serviceConnection: 'conn-dept-myapp-dev'
keyVault: 'kv-myapp-dev'
stappSlot: 'preview'
${{ if contains(variables['Build.SourceBranchName'], 'feat-') }}:
appSvc: 'app-dept-myapp-org-dev'
env: 'development'
serviceConnection: 'conn-dept-myapp-dev'
keyVault: 'kv-myapp-dev'
stappSlot: 'preview'
pool:
vmImage: ubuntu-latest
steps:
- script: |
echo '$(build.sourcebranchname) is building.'
echo 'This is a $(env) build.'
displayName: 'Build Information'
- checkout: self
- task: nodetool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js v16'
# pull appropriate variable from key vault
- task: AzureKeyVault@2
inputs:
azureSubscription: $(serviceConnection)
KeyVaultName: $(keyVault)
SecretsFilter: '*'
RunAsPreJob: true
# items under 'env' can be picked up with process.env.VAR_NAME
# they will not affect the rest of the pipeline
- script: |
npm install
npm run build
displayName: 'NPM Build'
env:
REACT_APP_APIM_AUTH_KEY: $(ApimAuthKey)
REACT_APP_APIM_URL: $(ApimUrl)
REACT_APP_APIM_EMPLOYEE_PATH: $(apimEmployeePath)
REACT_APP_APIM_FACILITY_PATH: $(ApimFacilityPath)
REACT_APP_myapp_CLIENT_ID: $(AzureClientID)
# Archive the application
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(System.DefaultWorkingDirectory)/build
includeRootFolder: false
archiveType: 'zip'
archiveFile: $(System.DefaultWorkingDirectory)/myappApp.zip
replaceExistingArchiv): true
# Publish as drop -- maybe not needed
# This drop not necessary as next step deploys,
# but could be used in staged deployment or for quick access to files
# for review purposes
- task: PublishBuildArtifacts@1
displayName: Publish app to drop artifact
inputs:
pathToPublish: $(System.DefaultWorkingDirectory)/myappApp.zip
artifactName: myappAppDrop
# Deploy directly to the to the App Service
- task: AzureWebApp@1
displayName: 'Azure WebApp deployment: $(appSvc)'
inputs:
azureSubscription: $(serviceConnection)
appType: 'webApp'
appName: $(appSvc)
package: $(System.DefaultWorkingDirectory)/myappApp.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment