Azure Dev Ops

Azure DevOps combines Git repository management with a suite of development tools, including CI/CD pipelines, project management, and more.

View as Markdown

Overview

By integrating Knapsack with Azure DevOps, you can streamline your design and development workflows, automate testing and deployment processes, and maintain a high level of code quality. Azure DevOps’ seamless integration with other Azure services also provides a cohesive environment for managing your entire development lifecycle.

Cloud Authoring

Authentication through Personal Access Token (PAT)

To enable cloud authoring within Azure, we use a Personal Access Token (PAT) for authentication. This token allows secure access to your Azure repositories and enables necessary actions on your behalf.

Step 1: Add Knapsack Bot

Add our Knapsack Bot (knapsack-bot@knapsack.cloud) to your repository as a collaborator with the necessary permissions.

Permissions Required

You may need administrative privileges on your repository to invite the Knapsack Bot as a collaborator. If you encounter any issues, please reach out to our support team for assistance.

Step 2: Token Generation

With Knapsack Bot added, we will take care of generating the token for you.

Important Notes

This is a manual process. If handling asynchronously, we’ll notify you when it is completed.

Mandatory Step

This step must be completed for Cloud Authoring to function.

Alternative Configuration

Generate and Securely Deliver a Token

Follow the below steps if your organization would prefer to completely own the PAT:

  1. Your organization handles generating a PAT.
  2. Securely deliver the token to us. We can arrange a live session to ensure secure delivery and setup.

Web Hooks

Integrating Repository Events with the Knapsack API

To synchronize repository-related events with the Knapsack UI, it’s crucial to set up web hooks. Specifically, we’ll configure two web hook triggers:

  1. “Pull request merge attempted”
  2. “Pull request updated”

This setup will automatically update the Knapsack UI when pull requests (PRs) are closed in Azure, such as removing a branch from the active branch list.

Steps to add the first web hook:

  1. Follow the guidelines in this article to get started.
  2. Navigate to “Service Hooks” under “Project Settings” (found in the bottom left corner).
  3. Click the “Add New” icon, then select “Web Hook”. Proceed by clicking “Next.”
  4. For the trigger, choose “Pull request merge attempted”.
  5. Ensure the appropriate repository is selected. Leave all other options set to “[Any]”.
  6. Click “Next.”
  7. In the settings section, input the following URL: https://api.knapsack.cloud/webhooks/azure.
  8. Conclude by clicking “Finish”.

Steps to add the second web hook:

  1. Repeat steps above with trigger set to “Pull request updated”
  2. All other settings should match the previous above steps

file-tsLRTt1fQN.png file-GbR3De3U0N.png


Azure Pipelines

Required Secret Variables

Deployments to Heroku rely on the following secret variables:

  1. HEROKU_EMAIL — The email associated with the Heroku account.
  2. HEROKU_API_KEY — The API Key associated with the Heroku account (found in profile settings)
  3. HEROKU_GIT_URL — Located on the app dashboard within Heroku’s admin interface
1trigger:
2- main
3
4pool:
5 vmImage: ubuntu-latest
6
7variables:
8- group: Heroku
9
10steps:
11- task: NodeTool@0
12 inputs:
13 versionSpec: '16.x'
14 displayName: 'Install Node.js'
15- checkout: self
16 fetchDepth: 1
17 displayName: 'Checkout source code'
18 persistCredentials: true
19- script: |
20 git fetch --all --unshallow
21 git checkout main
22 git pull
23- script: yarn install
24 displayName: 'yarn install'
25- script: yarn build
26 displayName: 'yarn build'
27- script: yarn test
28 displayName: 'Knapsack Test'
29- script: |
30 echo "machine git.heroku.com
31 login $(HEROKU_EMAIL)
32 password $(HEROKU_API_KEY)" > ~/.netrc
33 displayName: 'Write authentication credentials'
34- script: git status
35- script: |
36 git remote add heroku $(HEROKU_GIT_URL)
37 git push heroku main
38 displayName: 'Git push to Heroku for deploy'

Summary

  • The pipeline is triggered by changes to the main branch.
  • It uses an Ubuntu VM image and defines a variable group for Heroku credentials.
  • It installs Node.js, checks out the source code, and fetches the complete Git history.
  • It installs dependencies, builds the application, runs tests, and writes Heroku authentication credentials.
  • Finally, it pushes the main branch to Heroku for deployment.

This setup ensures that changes to the main branch are automatically built, tested, and deployed to Heroku.