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
20 changes: 19 additions & 1 deletion 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 } 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,7 @@ async function main(): Promise<void> {
var definitionIdSpecified: string = null;
var definitionIdTriggered: string = null;
var buildId: number = null;
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,12 +128,28 @@ 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", false));
Copy link
Contributor

Choose a reason for hiding this comment

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

we should make sure buildId is specified when the option chosen is specific build.

}
}

// verify that buildId belongs to the definition selected
if (definitionId) {
if (!buildId){
// get latest successful build filtered by branch
Copy link
Contributor

Choose a reason for hiding this comment

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

we should do this only when "latest build" option is chosen

var branchNameFilter = (branchName == "*") ? null : branchName;

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){
reject(tl.loc("BuildNotFound", buildId));
return;
}
buildId = buildsForThisDefinition[0].id
}

Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse the build we got in case version is latest or latestFromBranch instead of calling getBuild again in line 156?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, nice catch! Implemented & tested!

var build = await executeWithRetries("getBuild", () => buildApi.getBuild(buildId, projectId), 4).catch((reason) => {
reject(reason);
return;
Expand Down
26 changes: 24 additions & 2 deletions Tasks/DownloadBuildArtifacts/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": true,
"version": {
"Major": 0,
"Minor": 131,
"Minor": 132,
"Patch": 0
},
"groups": [
Expand Down Expand Up @@ -68,13 +68,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": "specificBuildId",
"type": "radio",
"label": "Download artifacts produced by",
"defaultValue": "specificNumber",
"visibleRule": "buildType == specific",
"required": true,
"options": {
"latest": "Latest",
"specificNumber": "Specific buildnumber"
},
"helpMarkDown": "Download artifacts produced by the latest build or by a specific build-number "
},
{
"name": "branchName",
"type": "string",
"label": "Branch name",
"defaultValue": "*",
"visibleRule": "buildType == specific && specificBuildId == latest",
"required": false,
"helpMarkDown": "Specify to filter on branch/ref name, for example: ```refs/heads/develop```. The default pattern (\\*) will download artifacts for all builds, not filtered by branch"
},
{
"name": "buildId",
"type": "pickList",
"label": "Build",
"defaultValue": "",
"required": true,
"visibleRule": "buildType == specific",
"visibleRule": "buildType == specific && specificBuildId == specificNumber",
"properties": {
"EditableOptions": "True",
"DisableManageLink": "True"
Expand Down