Skip to content

Commit b828623

Browse files
authored
Fix nightly build to pull correct CLI version from artifact feed (#4730)
1 parent b0d4915 commit b828623

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

eng/ci/templates/official/steps/download-latest-from-feed.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,8 @@ steps:
1010
- task: PowerShell@2
1111
displayName: 'Get latest artifact version'
1212
inputs:
13-
targetType: 'inline'
14-
script: |
15-
# Fetch the latest version of the func-cli package from the feed. All packages should have the
16-
# same package version as it is based on the CLI version + build number (which is date based)
17-
$packageUrl = "https://feeds.dev.azure.com/azfunc/internal/_apis/packaging/feeds/core-tools-nightly-build/packages/a998de77-f16c-4c10-af8c-cfa5a430eae7?api-version=7.1"
18-
$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
19-
20-
$response = Invoke-RestMethod -Uri $packageUrl -Headers $headers -Method Get
21-
$latestVersion = $response.versions[0].version
22-
23-
Write-Host "##vso[task.setvariable variable=FUNC_CLI_VERSION]$latestVersion"
24-
Write-Host "Using func-cli version: $latestVersion"
13+
targetType: 'filePath'
14+
filePath: '$(Build.SourcesDirectory)/eng/scripts/get-latest-package-versions.ps1'
2515
env:
2616
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
2717

@@ -41,7 +31,7 @@ steps:
4131
packageType: 'upack'
4232
feed: 'internal/core-tools-nightly-build'
4333
definition: 'func-cli-inproc'
44-
version: '$(FUNC_CLI_VERSION)'
34+
version: '$(FUNC_CLI_INPROC_VERSION)'
4535
downloadPath: '$(Pipeline.Workspace)/func-cli-inproc'
4636

4737
- task: DownloadPackage@1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Fetch the latest version of the func-cli package from the feed for each package
2+
$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
3+
4+
function Get-LatestPackageVersion {
5+
param($packageName)
6+
7+
$baseUrl = "https://feeds.dev.azure.com/azfunc/internal/_apis/packaging/feeds/core-tools-nightly-build"
8+
9+
$searchUrl = "$baseUrl/packages?packageNameQuery=$packageName&api-version=7.1"
10+
$searchResponse = Invoke-RestMethod -Uri $searchUrl -Headers $headers -Method Get
11+
$package = $searchResponse.value | Where-Object { $_.name -eq $packageName } | Select-Object -First 1
12+
13+
if ($package) {
14+
$packageUrl = "$baseUrl/packages/$($package.id)?api-version=7.1"
15+
$packageDetails = Invoke-RestMethod -Uri $packageUrl -Headers $headers -Method Get
16+
return $packageDetails.versions[0].version
17+
}
18+
return $null
19+
}
20+
21+
# Get version for each package
22+
$funcCliVersion = Get-LatestPackageVersion -packageName "func-cli"
23+
Write-Host "##vso[task.setvariable variable=FUNC_CLI_VERSION]$funcCliVersion"
24+
Write-Host "func-cli version: $funcCliVersion"
25+
26+
$funcCliInprocVersion = Get-LatestPackageVersion -packageName "func-cli-inproc"
27+
Write-Host "##vso[task.setvariable variable=FUNC_CLI_INPROC_VERSION]$funcCliInprocVersion"
28+
Write-Host "func-cli-inproc version: $funcCliInprocVersion"

0 commit comments

Comments
 (0)