VSTS扩展-获取构建URL

时间:2018-08-29 07:48:59

标签: azure-devops azure-pipelines azure-pipelines-release-pipeline

我正在用Javascript开发VSTS扩展。

在我的任务之一中,我需要获得指向我的构建结果的链接。 我尝试从{$ Build.BuildUri}中读取内容,但它给了我vstfs:///Build/Build/{buildId},而不是真实的链接。

我如何直接链接到我的构建结果?在构建和发布管道中都需要它。

1 个答案:

答案 0 :(得分:4)

构建结果页面使用如下格式的URL:

var ROWS = 7;
var COLS = 3;

function getIndex(row, col, COL) {
    return row * (COL + 1) + col;
}

function getIndices(range) {
    var start = range.start;
    var end = range.end;

    var startIndex = getIndex(start.row, start.col, COLS);
    var endIndex = getIndex(end.row, end.col, COLS);

    return { start: startIndex, end: endIndex };
}

function addRange(ranges, createdRange) {
    var createdRangeIndices = getIndices(createdRange);
    var hasOverlap = false;
    for (var i = 0; i < ranges.length; i++) {
        var currentRangeIndices = getIndices(ranges[i]);
        var overlap =
            createdRangeIndices.end < currentRangeIndices.start ||
            currentRangeIndices.end < createdRangeIndices.start;
        if (!overlap) {
            var start, end;
            if (currentRangeIndices.start < createdRangeIndices.start) {
                start = ranges[i].start;
            } else {
                start = createdRange.start;
            }
            if (currentRangeIndices.end > createdRangeIndices.end) {
                end = ranges[i].end;
            } else {
                end = createdRange.end;
            }
            ranges[i] = { start: start, end: end };
            hasOverlap = true;
            break;
        }
    }
    if (!hasOverlap) {
        // means the new range does not extend an existing range, so add it.
        ranges.push(createdRange);
    }
}

var ranges = []; // stores the range objects that are created earlier.
var rangesToAdd = [
    {
        start: { row: 2, col: 1 },
        end: { row: 6, col: 0 }
    },
    {
        start: { row: 6, col: 2 },
        end: { row: 7, col: 2 }
    },
    {
        start: { row: 3, col: 1 },
        end: { row: 6, col: 1 }
    },
    {
        start: { row: 6, col: 1 },
        end: { row: 6, col: 2 }
    }
];

rangesToAdd.forEach(aRange => addRange(ranges, aRange));
console.log(ranges);

您可以在构建过程中通过Predefined Build Variables获得这些信息。在构建任务中,获取以下变量,然后将它们组合到构建结果URL。

  
      
  • System.TeamFoundationCollectionUri
  •   
  • System.TeamProject
  •   
  • Build.BuildId
  •