当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript WebApi.getReleaseApi方法代码示例

本文整理汇总了TypeScript中vso-node-api/WebApi.WebApi.getReleaseApi方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WebApi.getReleaseApi方法的具体用法?TypeScript WebApi.getReleaseApi怎么用?TypeScript WebApi.getReleaseApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vso-node-api/WebApi.WebApi的用法示例。


在下文中一共展示了WebApi.getReleaseApi方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: run

async function run() {
    tl.debug("Starting Tag Build/Release task");

    let tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
    // try to get the build team project, in case it's different from the release team project
    let teamProject = tl.getVariable("Build.ProjectName");
    if (!teamProject || teamProject.length === 0) {
        // fall back on the release team project
        teamProject = tl.getVariable("System.TeamProject");
    }
    let type = tl.getInput("type", true);
    let tags = tl.getDelimitedInput("tags", '\n', true);

    let buildId = -1;
    let bId = tl.getVariable("Build.BuildId");
    // just for tests
    if (bId === "-1") {
        bId = null;
    }
    if (bId) {
        buildId = parseInt(bId);
        tl.debug(`Build ID = ${buildId}`);
    } else {
        if (type === "Build") {
            return completeTask(false, "No build ID found - perhaps Type should be 'Release' not 'Build'?");
        }
    }
    
    let releaseId = -1;
    let rId = tl.getVariable("Release.ReleaseId");
    if (rId) {
        releaseId = parseInt(rId);
        tl.debug(`Release ID = ${releaseId}`);
    } else {
        if (type === "Release") {
            return completeTask(false, "No release ID found - perhaps Type should be 'Build' not 'Release'?");
        } 
    }
        
    // handle creds
    let credHandler: vstsInterfaces.IRequestHandler;
    let accessToken = tl.getVariable("System.AccessToken");
    if (!accessToken || accessToken.length === 0) {
        tl.setResult(tl.TaskResult.Failed, "Could not find token for autheniticating. Please enable OAuth token in Build/Release Options.");
        tl.debug("Leaving Tag Build task");
        return;
    } else {
        tl.debug("Detected token: creating bearer cred handler");
        credHandler = webApi.getBearerHandler(accessToken);
    }

    let vsts = new webApi.WebApi(tpcUri, credHandler);
    
    if (type === "Build") {
        tl.debug("Getting build api client");
        let buildApi = vsts.getBuildApi();
        
        console.info(`Setting tags on build [${buildId}]`);
        await buildApi.addBuildTags(tags, teamProject, buildId)
            .then(tags => {
                tl.debug(`New tags: ${tags.join(',')}`);
                return completeTask(true, `Successfully added tags to the ${type}`);
            })
            .catch(e => tl.setResult(tl.TaskResult.Failed, e));
    } else {
        tl.debug("Getting release api client");

        let releaseResourceArea;
        try {
            let locationClient = vsts.getLocationsApi();
            releaseResourceArea = await locationClient.getResourceArea("efc2f575-36ef-48e9-b672-0c6fb4a48ac5");
        } catch (e) {
            console.warn("Could not get releaseResourceArea resource area: this may cause the task to fail.");
        }
        let releaseApi = vsts.getReleaseApi(releaseResourceArea ? releaseResourceArea.locationUrl : null);

        console.info(`Setting tags on release [${releaseId}]`);
        await releaseApi.addReleaseTags(tags, teamProject, releaseId)
            .then(tags => {
                tl.debug(`New tags: ${tags.join(',')}`);
                return completeTask(true, `Successfully added tags to the ${type}`);
            })
            .catch(e => completeTask(false, e));
    }
}
开发者ID:xiangyan99,项目名称:cols-agent-tasks,代码行数:85,代码来源:tagBuild.ts

示例2: parseInt

    var promise = new Promise<void>(async (resolve, reject) => {

        try {
            agentApi.logDebug("Starting Tag XplatGenerateReleaseNotes task");

            let tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
            let teamProject = tl.getVariable("System.TeamProject");
            let releaseId: number = parseInt(tl.getVariable("Release.ReleaseId"));
            let releaseDefinitionId: number = parseInt(tl.getVariable("Release.DefinitionId"));

            // Inputs
            let environmentName: string = (tl.getInput("overrideStageName") || tl.getVariable("Release_EnvironmentName")).toLowerCase();
            var templateLocation = tl.getInput("templateLocation", true);
            var templateFile = tl.getInput("templatefile");
            var inlineTemplate = tl.getInput("inlinetemplate");
            var outputfile = tl.getInput("outputfile", true);
            var outputVariableName = tl.getInput("outputVariableName");
            var emptyDataset = tl.getInput("emptySetText");

            let credentialHandler: vstsInterfaces.IRequestHandler = util.getCredentialHandler();
            let vsts = new webApi.WebApi(tpcUri, credentialHandler);
            var releaseApi: IReleaseApi = await vsts.getReleaseApi();
            var buildApi: IBuildApi = await vsts.getBuildApi();

            agentApi.logInfo("Getting the current release details");
            var currentRelease = await releaseApi.getRelease(teamProject, releaseId);

            if (!currentRelease) {
                reject(`Unable to locate the current release with id ${releaseId}`);
                return;
            }

            var environmentId = util.getReleaseDefinitionId(currentRelease.environments, environmentName);

            let mostRecentSuccessfulDeployment = await util.getMostRecentSuccessfulDeployment(releaseApi, teamProject, releaseDefinitionId, environmentId);
            let mostRecentSuccessfulDeploymentRelease: Release;

            agentApi.logInfo(`Getting all artifacts in the current release...`);
            var arifactsInThisRelease = util.getSimpleArtifactArray(currentRelease.artifacts);
            agentApi.logInfo(`Found ${arifactsInThisRelease.length}`);

            let arifactsInMostRecentRelease: util.SimpleArtifact[] = [];
            var mostRecentSuccessfulDeploymentName: string = "";
            if (mostRecentSuccessfulDeployment) {
                // Get the release that the deployment was a part of - This is required for the templating.
                mostRecentSuccessfulDeploymentRelease = await releaseApi.getRelease(teamProject, mostRecentSuccessfulDeployment.release.id);
                agentApi.logInfo(`Getting all artifacts in the most recent successful release [${mostRecentSuccessfulDeployment.release.name}]...`);
                arifactsInMostRecentRelease = util.getSimpleArtifactArray(mostRecentSuccessfulDeployment.release.artifacts);
                mostRecentSuccessfulDeploymentName = mostRecentSuccessfulDeployment.release.name;
                agentApi.logInfo(`Found ${arifactsInMostRecentRelease.length}`);
            } else {
                agentApi.logInfo(`Skipping fetching artifact in the most recent successful release as there isn't one.`);
                // we need to set the last successful as the current release to templates can get some data
                mostRecentSuccessfulDeploymentRelease = currentRelease;
            }

            var globalCommits: Change[] = [];
            var globalWorkItems: ResourceRef[] = [];

            for (var artifactInThisRelease of arifactsInThisRelease) {
                agentApi.logInfo(`Looking at artifact [${artifactInThisRelease.artifactAlias}]`);
                agentApi.logInfo(`Build Number: [${artifactInThisRelease.buildNumber}]`);

                var buildNumberFromMostRecentBuild = null;

                if (arifactsInMostRecentRelease.length > 0) {
                    agentApi.logInfo(`Looking for the [${artifactInThisRelease.artifactAlias}] in the most recent successful release [${mostRecentSuccessfulDeploymentName}]`);
                    for (var artifactInMostRecentRelease of arifactsInMostRecentRelease) {
                        if (artifactInThisRelease.artifactAlias.toLowerCase() === artifactInMostRecentRelease.artifactAlias.toLowerCase()) {
                            agentApi.logInfo(`Found artifact [${artifactInThisRelease.artifactAlias}] with build number [${artifactInThisRelease.buildNumber}] in release [${mostRecentSuccessfulDeploymentName}]`);

                            // Only get the commits and workitems if the builds are different
                            if (artifactInMostRecentRelease.buildNumber.toLowerCase() !== artifactInThisRelease.buildNumber.toLowerCase()) {
                                agentApi.logInfo(`Checking what commits and workitems have changed from [${artifactInMostRecentRelease.buildNumber}] => [${artifactInThisRelease.buildNumber}]`);

                                var commits = await buildApi.getChangesBetweenBuilds(teamProject, parseInt(artifactInMostRecentRelease.buildId),  parseInt(artifactInThisRelease.buildId), 5000);

                                var workitems = await buildApi.getWorkItemsBetweenBuilds(teamProject, parseInt(artifactInMostRecentRelease.buildId),  parseInt(artifactInThisRelease.buildId), 5000);

                                var commitCount: number = 0;
                                var workItemCount: number = 0;

                                if (commits) {
                                    commitCount = commits.length;
                                    globalCommits = globalCommits.concat(commits);
                                }

                                if (workitems) {
                                    workItemCount = workitems.length;
                                    globalWorkItems = globalWorkItems.concat(workitems);
                                }

                                agentApi.logInfo(`Detected ${commitCount} commits/changesets and ${workItemCount} workitems between the builds.`);
                            } else {
                                agentApi.logInfo(`Build for artifact [${artifactInThisRelease.artifactAlias}] has not changed.  Nothing to do`);
                            }
                        }
                    }
                }
                agentApi.logInfo(``);
//.........这里部分代码省略.........
开发者ID:Edgixshua,项目名称:vNextBuild,代码行数:101,代码来源:GenerateReleaseNotes.ts

示例3: parseInt

    var promise = new Promise<void>(async (resolve, reject) => {

        tl.setResourcePath(path.join(__dirname, "task.json"));

        tl.debug("Starting Tag ChangedBuildArtifacts task");

        let tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
        let teamProject = tl.getVariable("System.TeamProject");
        let hostType = tl.getVariable("system.hostType");
        let releaseId: number = parseInt(tl.getVariable("Release.ReleaseId"));
        let releaseDefinitionId: number = parseInt(tl.getVariable("Release.DefinitionId"));
        let releaseDefinitionEnvironmentId: number = parseInt(tl.getVariable("Release.DefinitionEnvironmentId"));
        let releaseEnvironmentName = tl.getVariable("Release.EnvironmentName");

        // Get the credential handler
        var accessToken: string = tl.getVariable("System.AccessToken");
        let credHandler: vstsInterfaces.IRequestHandler;
        if (!accessToken || accessToken.length === 0) {
            reject("Unable to locate access token.  Please make sure you have enabled the \"Allow scripts to access OAuth token\" setting.");
            return;
        } else {
            tl.debug("Creating the credential handler");
            // used for local debugging.  Allows switching between PAT token and Bearer Token for debugging
            credHandler = accessToken.length === 52 ? webApi.getPersonalAccessTokenHandler(accessToken) :
                                                    webApi.getBearerHandler(accessToken);
        }

        let vsts = new webApi.WebApi(tpcUri, credHandler);
        var releaseApi: IReleaseApi = await vsts.getReleaseApi();

        console.log("Getting the current release details");
        var currentRelease = await releaseApi.getRelease(teamProject, releaseId).catch((reason) => {
            reject(reason);
            return;
        });

        console.log(`Getting the all the successful deployments to release definition id ${releaseDefinitionEnvironmentId}`);
        // Gets the latest successful deployments in order
        var successfulDeployments = await releaseApi.getDeployments(teamProject, releaseDefinitionId, releaseDefinitionEnvironmentId, null, null, null, DeploymentStatus.Succeeded, null, true, null, null, null, null).catch((reason) => {
            reject(reason);
            return;
        });

        // We want to compare the artifacts between the two definitions to see which ones are different.
        if (currentRelease) {
            console.log(`Getting all artifacts in the current release...`);
            var arifactsInThisRelease = getArtifactArray(currentRelease.artifacts);
            console.log(`Found ${arifactsInThisRelease.length}`);

            if (successfulDeployments && successfulDeployments.length > 0) {
                // loop through every artifact in this release
                for (var artifactInCurrentRelease of arifactsInThisRelease) {
                    console.log(`Looking for artifact ${artifactInCurrentRelease.buildNumber} in previous successful deployments...`);
                    for (var deployment of successfulDeployments) {

                        // We need to check the status of this release
                        var releaseForDeployment = await releaseApi.getRelease(teamProject, deployment.release.id).catch((reason) => {
                            reject(reason);
                            return;
                        });

                        if (releaseForDeployment && releaseForDeployment.status !== ReleaseStatus.Active) {
                            // the release is not active
                            console.log(`Skipping this deployment because release [${deployment.release.name}] has a status of [${ReleaseStatus[releaseForDeployment.status]}]`);
                            continue;
                        }

                        if (!artifactInCurrentRelease.previouslyDeployed) {
                            console.log(`Searching for artifact ${artifactInCurrentRelease.buildNumber} in release ${deployment.release.name}`);
                            var artifactsInDeployment = getArtifactArray(deployment.release.artifacts);

                            for (var artifactInDeployment of artifactsInDeployment) {
                                if (artifactInCurrentRelease.buildDefinitionId === artifactInDeployment.buildDefinitionId &&
                                    artifactInCurrentRelease.buildNumber === artifactInDeployment.buildNumber) {
                                    console.log(`Found artifact ${artifactInCurrentRelease.buildNumber} deployed in ${deployment.release.name}`);
                                    artifactInCurrentRelease.previouslyDeployed = true;
                                    break;
                                }
                            }
                        } else {
                            console.log(`Skipping remaining releases because the property previouslyDeployed for artifact ${artifactInCurrentRelease.buildNumber} was false.`);
                            break;
                        }
                    }
                }
            }
            else {
                // There are no successful releases - we need to add all the artifacts
                console.log(`Past successful releases for id ${releaseDefinitionId} and environment id ${releaseDefinitionEnvironmentId} not found.`);
            }

            for (var artifactInCurrentRelease2 of arifactsInThisRelease) {
                var safeAlias = artifactInCurrentRelease2.artifactAlias.replace(/\./gi, "_");
                var variableName = ("RELEASE_ARTIFACTS_" + safeAlias + "_PreviouslyDeployed").toUpperCase();
                console.log(`Setting variable ${variableName} with value ${artifactInCurrentRelease2.previouslyDeployed}`);
                tl.setVariable(variableName, artifactInCurrentRelease2.previouslyDeployed.toString());
            }

        }
        else {
//.........这里部分代码省略.........
开发者ID:gregpakes,项目名称:ArtifactVariables,代码行数:101,代码来源:ArtifactDeploymentDetectorTask.ts


注:本文中的vso-node-api/WebApi.WebApi.getReleaseApi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。