Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cm.banner("Build Artifact Samples");
const project = cm.getProject();
console.log("project", project);
// get the latest successful build.
cm.heading(`Get latest successful build for ${project} project`);
const builds: bi.Build[] = await vstsBuild.getBuilds(
project,
null, // definitions: number[]
null, // queues: number[]
null, // buildNumber
null, //new Date(2016, 1, 1), // minFinishTime
null, // maxFinishTime
null, // requestedFor: string
bi.BuildReason.All, // reason
bi.BuildStatus.Completed,
bi.BuildResult.Succeeded,
null, // tagFilters: string[]
null, // properties: string[]
//bi.DefinitionType.Build,
1 // top: number
);
if (builds.length > 0) {
const latestBuild: bi.Build = builds[0];
console.log(`build ${latestBuild.id}`);
// Retrieve the list of artifacts for the latest build.
cm.heading(`Artifacts for build ${latestBuild.id}, ${project} project`);
const artifacts: bi.BuildArtifact[] = await vstsBuild.getArtifacts(project, latestBuild.id);
let downloadableArtifact;
// Azure util.
const Enum = require("enum");
const azureDevops = require("azure-devops-node-api");
const config = require("config");
const buildInterfaces = require("azure-devops-node-api/interfaces/BuildInterfaces");
const util = require("util");
const BuildStatus = new Enum(buildInterfaces.BuildStatus);
const BuildResult = new Enum(buildInterfaces.BuildResult);
const sleep = util.promisify(setTimeout);
const logger = require("./log")(module);
// Get build api.
const getBuildApi = async function() {
let authHandler = azureDevops.getPersonalAccessTokenHandler(
config.azureDevops.token
);
let conn = new azureDevops.WebApi(config.azureDevops.endpoint, authHandler);
let buildApi = await conn.getBuildApi();
return buildApi;
};
// Queue build in azure pipelines and return the build object.