azure-devops

A collection of templates and tools for use with Azure DevOps.

Installation#

azure-pipelines.yml

resources:
repositories:
- repository: frontend-packages
name: iqmetrix/frontend-packages
type: github
endpoint: Hub

Stages#

For most use cases, the stage template will be able to handle all your build and deployment needs.

Steps#

  1. Build the app (See Build for more details)
  2. Deploy to Int (See Deploy from more details)
    • [Optional] Create Sentry release (See Sentry for more details)
  3. Deploy to RC
  4. Deploy to Prod

Usage#

azure-pipelines.yml

stages:
- template: packages/utilities/azure-devops/stages.yml@frontend-packages
parameters: # Currently all parameters are optional.
build: # Parameters for the build stage
buildDir: "dist"

Parameters#

parameterrequireddefaultdescription
buildno{}Parameters to pass to the build job. See below for details.
sentryno{}Parameters to pass to the build job. See below for details.
deploy.buildPathno$(Pipeline.Workspace)/dropThe directory to find the app's build artifact in.
deploy.{env}no{}Parameters to pass to deploy stages by {env}.
deploy.{env}.environmentno{env}The Azure DevOps environment. Used for manual release approvals.
deploy.{env}.resourceGroupnohub-{env}The Azure resource group the appService is under.
deploy.{env}.subscriptionnoProd: SharedMicroservices-Production
Others: SharedMicroservices-Development
The Azure subscription the appService is under.
deploy.{env}.appServicenoThe Hub app service for the given environment. Eg. hub-{env}-westus1The Azure subscription to deploy the app to.
deploy.{env}.conditionnoInt: Not a PR and on the master, develop, or main branch
Others: The previous stage succeeded
deploy.{env}.dependsOnnoThe previous environment's deploy stage.The stage name to depend on prior to running this environment's deploy stage

Build#

A build job template is provided for apps under Hub DevOps Project.

Steps#

  1. Access GitHub Service User credentials from the BuildAndDeployShared-KV key vault
  2. Configure Git to fetch GitHub repositories with HTTPS and service user credentials. This is a compatibility fix for Hub v1 apps.
  3. Install Node.js
    • Uses the nodeVersion parameter
  4. Set variables
    • Sets the artifact output directory from the package.json homepage property
    • Detects if the repository is using npm or yarn as a package manager
  5. Authenticate NPM Registry
  6. Install dependencies with the detected package manager
  7. Build
  8. Replace version numbers in main.js for Hub v1 apps to cache bust
  9. Test
    • Sets the CI environment variable to true to disable test watching in react-scripts
  10. Create ping
    • Create a ping json file in buildDir with the name and version from package.json
  11. Copy Files
  12. Publish Build Artifacts

Usage#

azure-pipelines.yml

jobs:
- template: packages/utilities/azure-devops/build-pipeline.yml@frontend-packages
parameters: # Currently all parameters are optional.
buildDir: "dist"
parameterrequireddefaultdescription
hubVersionno3The version of the Hub framework to build
buildDirno'build'The directory containing the build output
nodeVersionno'12.x'Node.js version pattern Azure DevOps docs
poolnovmImage: 'ubuntu-16.04'The pool option value Azure DevOps Docs
workingDirectoryno'.'The directory of where your web project to build resides (if it is not in the root of the repo). This is where npm will be run.

Deploy#

A deploy stage template is provided for deploying Hub Apps to a single environment.

Steps#

  1. Validate parameters
  2. Start Azure App Service staging slot
  3. Delete the previous app folder contents in the staging slot
  4. Upsert the app folder to the provided Azure App Service staging slot
  5. Check ping endpoints for the hub.app and for the deployed app on staging slot
  6. Delete the previous app folder contents in the production slot
  7. Upsert the app folder to the provided Azure App Service production slot
  8. Stop Azure App Service staging slot

Usage#

azure-pipelines.yml

stages:
- stage: Int
jobs:
- template: packages/utilities/azure-devops/deploy.yml@frontend-packages
parameters:
environment: Int
subscription: Some-Subscription
appService: Some-App-Service
resourceGroup: Some-Resource-Group
buildPath: ./drop
parameterrequireddefaultdescription
environmentyesThe name of the Azure DevOps environment
subscriptionyesThe Azure subscription the App Service is under
appServiceyesThe name of the App Service to deploy to
resourceGroupyesThe name of the resource group where the App service is located
buildPathyesThe path to the downloaded artifact. This contains the Hub App bundle.

Sentry#

An optional Sentry stage template is provided for creating Releases in Sentry and uploading sourcemaps. This will pre-create a Release in Sentry in which your application code can report against.

If you intend to utilize this feature, please ensure that Sentry is properly initialized in your application code.

Steps#

  1. Grabs Sentry credentials from Key Vault
  2. Installs Node.js
    • Uses the nodeVersion parameter
  3. Install sentry-cli
  4. Create Release in Sentry
    • Uses {package.json name}@{package.json version} format for release name

Usage#

azure-pipelines.yml

stages:
- template: packages/utilities/azure-devops/stages.yml@frontend-packages
parameters:
sentry:
project: hub-apps
parameterrequireddefaultdescription
projectyesThe name of the Sentry project. Should be the same Project in which you initialize Sentry with (via the DSN).
nodeVersionno'12.x'Node.js version pattern Azure DevOps docs

Sources#

Last updated on by Steven Lu