Path: blob/main/build/azure-pipelines/common/checkForArtifact.ts
3520 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Artifact, requestAZDOAPI } from './publish';6import { retry } from './retry';78async function getPipelineArtifacts(): Promise<Artifact[]> {9const result = await requestAZDOAPI<{ readonly value: Artifact[] }>('artifacts');10return result.value.filter(a => !/sbom$/.test(a.name));11}1213async function main([variableName, artifactName]: string[]): Promise<void> {14if (!variableName || !artifactName) {15throw new Error(`Usage: node checkForArtifact.js <variableName> <artifactName>`);16}1718try {19const artifacts = await retry(() => getPipelineArtifacts());20const artifact = artifacts.find(a => a.name === artifactName);21console.log(`##vso[task.setvariable variable=${variableName}]${artifact ? 'true' : 'false'}`);22} catch (err) {23console.error(`ERROR: Failed to get pipeline artifacts: ${err}`);24console.log(`##vso[task.setvariable variable=${variableName}]false`);25}26}2728main(process.argv.slice(2))29.then(() => {30process.exit(0);31}, err => {32console.error(err);33process.exit(1);34});353637