How to use azure-devops-node-api - 10 common examples

To help you get started, we’ve selected a few azure-devops-node-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openupm / openupm / scripts / examples / build-azure-pipelines.js View on Github external
build_name: getBuildName('x', '@rotorz/unity3d-localized-strings', '1.0.3'),
          // 'system.debug': true,
          // 'agent.diagnostic': true,
        }
      )
  }, config.azureDevops.project);
  for (let i = 0; i < config.azureDevops.retries; i++) {
    await sleep(config.azureDevops.retryIntervalStep * (i + 1));
    build = await buildApi.getBuild(config.azureDevops.project, build.id);
    let statusName = BuildStatusEnum.getKeyOrThrow(build.status);
    let resultName = typeof build.result === 'undefined'
      ? 'undefined'
      : BuildResultEnum.getKeyOrThrow(build.result);
    console.log(`status: ${statusName}, result: ${resultName}`);
    switch (build.status) {
      case BuildStatus.Completed:
      case BuildStatus.Cancelling:
      case BuildStatus.Postponed:
        return build;
      case BuildStatus.None:
      case BuildStatus.InProgress:
      case BuildStatus.NotStarted:
        break;
      default:
        throw new Error(`Unknown build status ${build.status}`);
    }
  }
};
github microsoft / azure-devops-node-api / samples / buildArtifact.ts View on Github external
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;
            for (const artifact of artifacts) {
github microsoft / azure-pipelines-tasks / Tasks / DownloadBuildArtifactsV0 / main.ts View on Github external
definitionId = String(definitions[0].id);
                console.log(tl.loc("DefinitionNameMatchFound", definitionIdSpecified, definitionId));
            }

            if (!definitionId) {
                reject(tl.loc("UnresolvedDefinitionId"));
                return;
            }
        }

        // verify that buildId belongs to the definition selected
        if (definitionId) {
            var build: Build;
            if (buildVersionToDownload != "specific" && !triggeringBuildFound) {
                var resultFilter = BuildResult.Succeeded;
                if (allowPartiallySucceededBuilds) {
                    resultFilter |= BuildResult.PartiallySucceeded;
                }
                var branchNameFilter = (buildVersionToDownload == "latest") ? null : branchName;

                // get latest successful build filtered by branch
                var buildsForThisDefinition = await executeWithRetries("getBuildId", () => buildApi.getBuilds(projectId, [parseInt(definitionId)], null, null, null, null, null, null, BuildStatus.Completed, resultFilter, tagFilters, null, null, null, null, null, BuildQueryOrder.FinishTimeDescending, branchNameFilter), retryLimit).catch((reason) => {
                    reject(reason);
                    return;
                });

                if (!buildsForThisDefinition || buildsForThisDefinition.length == 0) {
                    if (buildVersionToDownload == "latestFromBranch") reject(tl.loc("LatestBuildFromBranchNotFound", branchNameFilter));
                    else reject(tl.loc("LatestBuildNotFound"));
                    return;
                }
github microsoft / azure-devops-node-api / samples / buildArtifact.ts View on Github external
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;
github openupm / openupm / scripts / examples / build-azure-pipelines.js View on Github external
// 'system.debug': true,
          // 'agent.diagnostic': true,
        }
      )
  }, config.azureDevops.project);
  for (let i = 0; i < config.azureDevops.retries; i++) {
    await sleep(config.azureDevops.retryIntervalStep * (i + 1));
    build = await buildApi.getBuild(config.azureDevops.project, build.id);
    let statusName = BuildStatusEnum.getKeyOrThrow(build.status);
    let resultName = typeof build.result === 'undefined'
      ? 'undefined'
      : BuildResultEnum.getKeyOrThrow(build.result);
    console.log(`status: ${statusName}, result: ${resultName}`);
    switch (build.status) {
      case BuildStatus.Completed:
      case BuildStatus.Cancelling:
      case BuildStatus.Postponed:
        return build;
      case BuildStatus.None:
      case BuildStatus.InProgress:
      case BuildStatus.NotStarted:
        break;
      default:
        throw new Error(`Unknown build status ${build.status}`);
    }
  }
};
github microsoft / azure-devops-node-api / samples / buildArtifact.ts View on Github external
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);
github microsoft / azure-pipelines-tasks / Tasks / DownloadBuildArtifactsV0 / main.ts View on Github external
console.log(tl.loc("DefinitionNameMatchFound", definitionIdSpecified, definitionId));
            }

            if (!definitionId) {
                reject(tl.loc("UnresolvedDefinitionId"));
                return;
            }
        }

        // verify that buildId belongs to the definition selected
        if (definitionId) {
            var build: Build;
            if (buildVersionToDownload != "specific" && !triggeringBuildFound) {
                var resultFilter = BuildResult.Succeeded;
                if (allowPartiallySucceededBuilds) {
                    resultFilter |= BuildResult.PartiallySucceeded;
                }
                var branchNameFilter = (buildVersionToDownload == "latest") ? null : branchName;

                // get latest successful build filtered by branch
                var buildsForThisDefinition = await executeWithRetries("getBuildId", () => buildApi.getBuilds(projectId, [parseInt(definitionId)], null, null, null, null, null, null, BuildStatus.Completed, resultFilter, tagFilters, null, null, null, null, null, BuildQueryOrder.FinishTimeDescending, branchNameFilter), retryLimit).catch((reason) => {
                    reject(reason);
                    return;
                });

                if (!buildsForThisDefinition || buildsForThisDefinition.length == 0) {
                    if (buildVersionToDownload == "latestFromBranch") reject(tl.loc("LatestBuildFromBranchNotFound", branchNameFilter));
                    else reject(tl.loc("LatestBuildNotFound"));
                    return;
                }

                build = buildsForThisDefinition[0];
github openupm / openupm / scripts / examples / build-azure-pipelines.js View on Github external
const buildAzurePipelines = async function () {
  let authHandler = azureDevops.getPersonalAccessTokenHandler(config.azureDevops.token);
  let conn = new azureDevops.WebApi(config.azureDevops.endpoint, authHandler);
  var buildApi = await conn.getBuildApi();
  let build = await buildApi.queueBuild({
    definition: {
      id: config.azureDevops.definitionId,
    },
    parameters:
      JSON.stringify(
        {
          repo_url: 'https://github.com/rotorz/unity3d-localized-strings.git',
          repo_branch: 'v1.0.3',
          package_name: '@rotorz/unity3d-localized-strings',
          package_ver: '1.0.3',
          build_name: getBuildName('x', '@rotorz/unity3d-localized-strings', '1.0.3'),
          // 'system.debug': true,
          // 'agent.diagnostic': true,
        }
github openupm / openupm / scripts / examples / build-azure-pipelines.js View on Github external
const buildAzurePipelines = async function () {
  let authHandler = azureDevops.getPersonalAccessTokenHandler(config.azureDevops.token);
  let conn = new azureDevops.WebApi(config.azureDevops.endpoint, authHandler);
  var buildApi = await conn.getBuildApi();
  let build = await buildApi.queueBuild({
    definition: {
      id: config.azureDevops.definitionId,
    },
    parameters:
      JSON.stringify(
        {
          repo_url: 'https://github.com/rotorz/unity3d-localized-strings.git',
          repo_branch: 'v1.0.3',
          package_name: '@rotorz/unity3d-localized-strings',
          package_ver: '1.0.3',
          build_name: getBuildName('x', '@rotorz/unity3d-localized-strings', '1.0.3'),
          // 'system.debug': true,
          // 'agent.diagnostic': true,
github microsoft / azure-pipelines-agent / release / createAdoPrs.js View on Github external
const INTEGRATION_DIR = path.join(__dirname, '..', '_layout', 'integrations');
const GIT = 'git';

var opt = require('node-getopt').create([
    ['',  'dryrun',               'Dry run only, do not actually commit new release'],
    ['h', 'help',                 'Display this help'],
  ])
  .setHelp(
    'Usage: node createAdoPrs.js [OPTION] \n' +
    '\n' +
    '[[OPTIONS]]\n'
  )
  .bindHelp()     // bind option 'help' to default action
  .parseSystem(); // parse command line

const authHandler = azdev.getPersonalAccessTokenHandler(process.env.PAT);
const connection = new azdev.WebApi('https://dev.azure.com/mseng', authHandler);

function createIntegrationFiles(newRelease, callback)
{
    fs.mkdirSync(INTEGRATION_DIR, { recursive: true });
    fs.readdirSync(INTEGRATION_DIR).forEach( function(entry) {
        if (entry.startsWith('PublishVSTSAgent-'))
        {
            // node 12 has recursive support in rmdirSync
            // but since most of us are still on node 10
            // remove the files manually first
            var dirToDelete = path.join(INTEGRATION_DIR, entry);
            fs.readdirSync(dirToDelete).forEach( function(file) {
                fs.unlinkSync(path.join(dirToDelete, file));
            });
            fs.rmdirSync(dirToDelete, { recursive: true });