Skip to content

Instantly share code, notes, and snippets.

@NenoLoje
Last active October 28, 2019 18:15
Show Gist options
  • Save NenoLoje/1a92b405e3f548b4dc0d0f3d6f5abb95 to your computer and use it in GitHub Desktop.
Save NenoLoje/1a92b405e3f548b4dc0d0f3d6f5abb95 to your computer and use it in GitHub Desktop.
[Azure Pipelines] Sample Pipeline #2 for node.js app with a deployment stage (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'
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
- stage: Deploy
displayName: 'Deploy (DEV)'
#condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
variables:
Azure.Region: 'North Europe'
Azure.ResourceGroup: 'prep-ct19-dev-rg'
Azure.WebAppName: 'prep-ct19-dev'
Azure.HostingPlan: 'prep-ct19-dev-plan'
Azure.WebAppUrl: 'https://prep-ct19-dev.azurewebsites.net'
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: $(Azure.ResourceGroup)
location: $(Azure.Region)
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)/ArmTemplates/windows-webapp-template.json'
overrideParameters: '-webAppName $(Azure.WebAppName) -hostingPlanName $(Azure.HostingPlan) -appInsightsLocation "$(Azure.Region)" -sku "F1 Free"'
deploymentMode: 'Complete'
- task: AzureWebApp@1
displayName: 'Deploy web app'
inputs:
azureSubscription: 'Free Trial'
appType: 'webApp'
appName: '$(Azure.WebAppName)'
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 $(Azure.WebAppUrl)'
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