Skip to content

Instantly share code, notes, and snippets.

@NenoLoje
Created October 28, 2019 18:14
Show Gist options
  • Save NenoLoje/44738f9f6518c4269585d859b94e33a9 to your computer and use it in GitHub Desktop.
Save NenoLoje/44738f9f6518c4269585d859b94e33a9 to your computer and use it in GitHub Desktop.
[Azure Pipelines] Sample Pipeline #3 for node.js app with multiple deployment stages (from code.talks 2019 demo)
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
stages:
- stage: Build
jobs:
- job: Build
displayName: "Build sources"
pool:
vmImage: 'windows-latest' # or: 'ubuntu-latest'
steps:
- task: UseNode@1
displayName: 'Use Node.js 8.10.0'
inputs:
version: '8.10.0'
- task: Npm@1
displayName: 'Install application dependencies'
inputs:
command: 'install'
workingDir: 'Application'
- task: Npm@1
displayName: 'Install test dependencies'
inputs:
command: 'install'
workingDir: 'Tests'
- task: Gulp@1
displayName: 'Run unit tests'
inputs:
gulpFile: 'Tests/gulpfile.js'
targets: 'unittest'
gulpjs: 'Tests/node_modules/gulp/bin/gulp.js'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'Unit Tests'
- task: ArchiveFiles@2
displayName: 'Archive application'
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/Application'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.StagingDirectory)/Application/$(Build.BuildId).zip'
- publish: '$(Build.StagingDirectory)/Application'
displayName: 'Publish artifact: Application'
artifact: 'Application'
- publish: '$(Build.SourcesDirectory)/Tests'
displayName: 'Publish artifact: Tests'
artifact: 'Tests'
- publish: '$(Build.SourcesDirectory)/armTemplates'
displayName: 'Publish artifact: ArmTemplates'
artifact: 'ArmTemplates'
# Requires extension: https://marketplace.visualstudio.com/items?itemName=jessehouwing.vsts-ensure-tests-tasks
- job: EnsureTests
displayName: 'Ensure test results exist'
dependsOn: Build
pool: server
steps:
- task: Ensure tests have executed.@0
inputs:
minNumOfExpectedTests: 1
- template: BuildTemplates/deploy.yml
parameters:
name: 'DEV'
azureRegion: 'North Europe'
azureResourceGroup: 'prep-ct19-dev-rg'
azureWebAppName: 'prep-ct19-dev'
azureHostingPlan: 'prep-ct19-dev-plan'
azureWebAppUrl: 'https://prep-ct19-dev.azurewebsites.net'
- template: BuildTemplates/deploy.yml
parameters:
name: 'QA'
azureRegion: 'North Europe'
azureResourceGroup: 'prep-ct19-qa-rg'
azureWebAppName: 'prep-ct19-qa'
azureHostingPlan: 'prep-ct19-qa-plan'
azureWebAppUrl: 'https://prep-ct19-qa.azurewebsites.net'
- template: BuildTemplates/deploy.yml
parameters:
name: 'PROD'
azureRegion: 'North Europe'
azureResourceGroup: 'prep-ct19-prod-rg'
azureWebAppName: 'prep-ct19-prod'
azureHostingPlan: 'prep-ct19-prod-plan'
azureWebAppUrl: 'https://prep-ct19-prod.azurewebsites.net'
parameters:
name: ''
azureRegion: ''
azureResourceGroup: ''
azureWebAppName: ''
azureHostingPlan: ''
azureWebAppUrl: ''
stages:
- stage: Deploy_${{ parameters.name }}
displayName: 'Deploy (${{ parameters.name }})'
#condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- job: Deploy
displayName: 'Deploy web app'
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: none
- download: current
displayName: 'Download artifact: Application'
artifact: 'Application'
- download: current
displayName: 'Download artifact: ArmTemplates'
artifact: 'ArmTemplates'
- task: AzureResourceManagerTemplateDeployment@3
displayName: 'Deploy Azure infrastructure'
inputs:
deploymentScope: 'Resource Group'
ConnectedServiceName: 'Free Trial'
subscriptionName: '88286652-83dd-4bc8-a04a-78b7f1a1471f'
action: 'Create Or Update Resource Group'
resourceGroupName: ${{ parameters.azureResourceGroup }}
location: ${{ parameters.azureRegion }}
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)/ArmTemplates/windows-webapp-template.json'
overrideParameters: '-webAppName ${{ parameters.azureWebAppName }} -hostingPlanName ${{ parameters.azureHostingPlan }} -appInsightsLocation "${{ parameters.azureRegion }}" -sku "F1 Free"'
deploymentMode: 'Complete'
- task: AzureWebApp@1
displayName: 'Deploy web app'
inputs:
azureSubscription: 'Free Trial'
appType: 'webApp'
appName: '${{ parameters.azureWebAppName }}'
package: '$(Pipeline.Workspace)/**/*.zip'
deploymentMethod: 'auto'
- job: Test
dependsOn: Deploy
displayName: 'Run functional tests'
pool:
vmImage: 'windows-latest'
steps:
- checkout: none
- download: current
displayName: 'Download artifact: Tests'
artifact: 'Tests'
- task: UseNode@1
displayName: 'Use Node.js 8.10.0'
inputs:
version: '8.10.0'
- task: Gulp@1
displayName: 'Run Selenium tests'
inputs:
gulpFile: '$(Pipeline.Workspace)/Tests/gulpfile.js'
targets: 'functionaltest'
arguments: '--webAppUrl ${{ parameters.azureWebAppUrl }}'
publishJUnitResults: true
testResultsFiles: '$(Pipeline.Workspace)/TestResults/TEST-RESULT.xml'
testRunTitle: 'Functional Tests'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment