New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

azdo-cancel-previous-builds

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azdo-cancel-previous-builds

Cancels all previous Azure Devops builds. Meant to be run from an Azure Devops pipeline

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

azdo-cancel-previous-builds

Node.js CI

This is a command-line script that will cancel any previous in-progress Azure Devops builds.

How it works

By using the environment variables set within Azure Devops pipelines, this script will query the Azure Devops API to find previous runs of this pipeline on the same branch.

It will then cancel these builds.

Usage

From your Azure Devops pipeline, include a script task to include Node (v10 or up), and then execute the script:

- task: NodeTool@0
  displayName: Install node
  inputs:
    versionSpec: 17.x
- script: npx azdo-cancel-previous-builds
  displayName: Cancel previous builds
  env:
    System.AccessToken: $(System.AccessToken)

Since the System.AccessToken is a secret variable, you need to explitly add it to make it available.

Note: The access token needs to have the 'read builds' and 'update builds' permission.
You can also use a custom access token that has these permissions.

The script requires these environment variables, which should be present in the context of an Azure Devops build:

  • System.TeamFoundationCollectionUri: The base URL to the Azure Devops collection
  • System.TeamProject: The name of the project
  • System.DefinitionId: The ID of the build definition
  • Build.BuildId: The ID of the current build
  • Build.SourceBranch: The current source code branch being built
  • System.AccessToken: A private access token
    This one needs to be explitly added like in the example above.

Development

First, run npm install to install dependencies.

Second, this script depends on certain environment variables to be present. To simulate this locally, create a file called .env and fill this with:

SYSTEM_ACCESSTOKEN=<your azure devops private access token>
SYSTEM_TEAMFOUNDATIONCOLLECTIONURI=https://dev.azure.com/<your organization>
SYSTEM_TEAMPROJECT=<your project>
SYSTEM_DEFINITIONID=<a build definition id>
BUILD_BUILDID=<a build id>
BUILD_SOURCEBRANCH=<a branch, e.g. refs/heads/master>

To run the script once, enter:

npm run start

To run the script on every change, enter:

npm run dev

Keywords

FAQs

Package last updated on 11 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc