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


TypeScript WebApi.getLocationsApi方法代码示例

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


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


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