Skip to content

Commit 52da120

Browse files
authored
Merge pull request #134 from coloursofnoise/main
Allow user-specified reasonFilter for retrieving builds
2 parents bb6fc7f + b166a57 commit 52da120

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ Every Azure Pipeline has a numerical identifier that is part of the URL. For exa
4646

4747
Pipelines can have an arbitrary number of artifacts, which are identified by a name. The `artifact` parameter specifies which one to download. It can be omitted if the given Pipeline run has only one artifact attached to it.
4848

49+
### Build filters
50+
51+
The `reasonFilter` parameter can be added to filter by the reason for a build.
52+
A list of accepted reasons can be found [here](https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0#buildreason). This parameter defaults to `all` if omitted.
53+
4954
### Strip prefix
5055

5156
Pipeline artifacts can contain entire directory structures. The `stripPrefix` parameter allows filtering by a given path prefix; Any files matching that prefix will be written (after stripping the prefix), all other files will be skipped.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ inputs:
2828
required: false
2929
description: 'Use @actions/cache to accelerate this Action'
3030
default: 'true'
31+
reasonFilter:
32+
required: false
33+
description: 'Filter results by the reason for the build; Defaults to "all"'
34+
default: 'all'
3135
runs:
3236
using: 'node12'
3337
main: 'dist/index.js'

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ async function run(): Promise<void> {
1515
core.getInput('repository'),
1616
core.getInput('definitionId'),
1717
core.getInput('artifact'),
18-
core.getInput('stripPrefix')
18+
core.getInput('stripPrefix'),
19+
core.getInput('reasonFilter')
1920
)
2021
const outputDirectory = core.getInput('path') || artifactName
2122
let useCache = core.getInput('cache') === 'true'

src/downloader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export async function get(
115115
repository: string,
116116
definitionId: string,
117117
artifactName: string,
118-
stripPrefix?: string
118+
stripPrefix?: string,
119+
reasonFilter = 'all'
119120
): Promise<{
120121
artifactName: string
121122
stripPrefix: string
@@ -137,7 +138,7 @@ export async function get(
137138
count: number
138139
value: [{id: string; downloadURL: string}]
139140
}>(
140-
`${baseURL}?definitions=${definitionId}&statusFilter=completed&resultFilter=succeeded&$top=1`
141+
`${baseURL}?definitions=${definitionId}&statusFilter=completed&resultFilter=succeeded&reasonFilter=${reasonFilter}&$top=1`
141142
)
142143
if (data.count !== 1) {
143144
throw new Error(`Unexpected number of builds: ${data.count}`)

0 commit comments

Comments
 (0)