-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 4 commits
494949e
d54d4fc
e9ac698
7b77c18
2fc8e9a
2fb5edb
fb71712
28a5f97
71e6d09
cad3594
f17b01a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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); | ||
|
||
|
@@ -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)); | ||
} | ||
} | ||
|
||
// verify that buildId belongs to the definition selected | ||
if (definitionId) { | ||
if (!buildId){ | ||
// get latest successful build filtered by branch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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.