Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DownloadBuildArtifacts - Use latest build filtered by branch #6356

Merged
merged 11 commits into from
Mar 22, 2018
34 changes: 29 additions & 5 deletions Tasks/DownloadBuildArtifacts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as tl from 'vsts-task-lib/task';
import { IBuildApi } from './vso-node-api/BuildApi';
import { IRequestHandler } from './vso-node-api/interfaces/common/VsoBaseInterfaces';
import { WebApi, getHandlerFromToken } from './vso-node-api/WebApi';
import { BuildStatus, BuildResult, BuildQueryOrder, Build } from './vso-node-api/interfaces/BuildInterfaces';

import * as models from 'artifact-engine/Models';
import * as engine from 'artifact-engine/Engine';
Expand Down Expand Up @@ -64,6 +65,8 @@ async function main(): Promise<void> {
var definitionIdSpecified: string = null;
var definitionIdTriggered: string = null;
var buildId: number = null;
var buildVersionToDownload: string = tl.getInput("buildVersionToDownload", false);
var branchName: string = tl.getInput("branchName", false);;
var downloadPath: string = tl.getInput("downloadPath", true);
var downloadType: string = tl.getInput("downloadType", true);

Expand Down Expand Up @@ -126,16 +129,37 @@ async function main(): Promise<void> {
// Triggering build info not found, or requested, default to specified build info
projectId = tl.getInput("project", true);
definitionId = definitionIdSpecified;
buildId = parseInt(tl.getInput("buildId", true));
buildId = parseInt(tl.getInput("buildId", buildVersionToDownload == "specific"));
}
}

// verify that buildId belongs to the definition selected
if (definitionId) {
var build = await executeWithRetries("getBuild", () => buildApi.getBuild(buildId, projectId), 4).catch((reason) => {
reject(reason);
return;
});
var build : Build;
if (buildVersionToDownload != "specific"){
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,BuildResult.Succeeded,null,null,null,null,null,null, BuildQueryOrder.FinishTimeDescending,branchNameFilter), 4).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];
console.log(tl.loc("LatestBuildFound", build.id));
buildId = build.id
}
if (!build){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave blank line after previous if block

build = await executeWithRetries("getBuild", () => buildApi.getBuild(buildId, projectId), 4).catch((reason) => {
reject(reason);
return;
});
}

if (build) {
if (!build.definition || build.definition.id !== parseInt(definitionId)) {
Expand Down
31 changes: 28 additions & 3 deletions Tasks/DownloadBuildArtifacts/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 132,
"Minor": 133,
"Patch": 0
},
"groups": [
Expand Down Expand Up @@ -67,13 +67,35 @@
"visibleRule": "buildType == specific",
"helpMarkDown": "If checked, this build task will try to download artifacts from the triggering build. If there is no triggering build from the specified definition, it will download artifacts from the build specified in the options below."
},
{
"name": "buildVersionToDownload",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

folks only see the label. Is there a reason to rename the name? It will cause the tasks to get redownloaded since I believe the folder is by name + guid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean to yaml and all our docs and templates? Is this rename really worth it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a naming change of a field that is added as part of this feature (initially implemented by me, named 'artifactVersion'). On top of that, this is only a renaming of this parameter, not the renaming of the whole step. I dont think this is breaking in any way. With this, I dont see how this affects the yaml/docs... Or am I missing something here?

"type": "pickList",
"label": "Build version to download",
"defaultValue": "latest",
"visibleRule": "buildType == specific",
"required": true,
"options": {
"latest": "Latest",
"latestFromBranch": "Latest from specific branch",
"specific": "Specific version"
}
},
{
"name": "branchName",
"type": "string",
"label": "Branch name",
"defaultValue": "refs/heads/master",
"visibleRule": "buildType == specific && buildVersionToDownload == latestFromBranch",
"required": true,
"helpMarkDown": "Specify to filter on branch/ref name, for example: ```refs/heads/develop```."
},
{
"name": "buildId",
"type": "pickList",
"label": "Build",
"defaultValue": "",
"required": true,
"visibleRule": "buildType == specific",
"visibleRule": "buildType == specific && buildVersionToDownload == specific",
"properties": {
"EditableOptions": "True",
"DisableManageLink": "True"
Expand Down Expand Up @@ -196,6 +218,9 @@
"ArtifactsSuccessfullyDownloaded": "Successfully downloaded artifacts to %s",
"RetryingOperation" : "Error : in %s, so retrying => retries pending : %s",
"OperationFailed": "Failed in %s with error: %s",
"ArtifactNameDirectoryNotFound": "Directory '%s' does not exist. Falling back to parent directory: %s"
"ArtifactNameDirectoryNotFound": "Directory '%s' does not exist. Falling back to parent directory: %s",
"LatestBuildFound": "Latest build found: %s",
"LatestBuildNotFound":"Latest build not found",
"LatestBuildFromBranchNotFound":"Latest build from branch %s not found"
}
}