Skip to content

Commit a05f4b2

Browse files
authored
Use Find-PSResource to Azure Artifacts instead of Find-Module to PSGallery (#27942)
1 parent 0d8eb9e commit a05f4b2

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tools/RunVersionController.ps1

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,28 @@ function Bump-AzVersion
176176
$localAz = Import-PowerShellDataFile -Path "$PSScriptRoot\Az\Az.psd1"
177177
Write-Host "Getting Az $ReleaseType information from gallery..." -ForegroundColor Yellow
178178
if("LTS" -eq $ReleaseType){
179-
$galleryAz = (Find-Module -Name Az -Repository $GalleryName -AllVersions | Where-Object {([System.Version]($_.Version)).Major%2 -eq 0} | Sort-Object {[System.Version]$_.Version} -Descending)[0]
180-
}else{
181-
$galleryAz = Find-Module -Name Az -Repository $GalleryName
179+
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
180+
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
181+
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
182+
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
183+
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
184+
}
185+
else {
186+
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName -Version *
187+
}
188+
$galleryAz = $galleryAz | Where-Object { ([System.Version]($_.Version)).Major%2 -eq 0 } | Sort-Object {[System.Version]$_.Version} -Descending
189+
}
190+
else
191+
{
192+
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
193+
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
194+
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
195+
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
196+
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
197+
}
198+
else {
199+
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName
200+
}
182201
}
183202

184203
$versionBump = [PSVersion]::NONE
@@ -325,7 +344,15 @@ function Update-AzPreviewChangelog
325344
$AzPreviewVersion = (Import-PowerShellDataFile "$PSScriptRoot\Az\Az.psd1").ModuleVersion
326345
$localAz = Import-PowerShellDataFile -Path "$PSScriptRoot\AzPreview\AzPreview.psd1"
327346
Write-Host "Getting gallery AzPreview information..." -ForegroundColor Yellow
328-
$galleryAz = Find-Module -Name AzPreview -Repository $GalleryName
347+
if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
348+
Write-Host "Using DEFAULT_PS_REPOSITORY_NAME: $Env:DEFAULT_PS_REPOSITORY_NAME"
349+
$AccessTokenSecureString = $env:SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString -AsPlainText -Force
350+
$credentialsObject = [pscredential]::new("ONEBRANCH_TOKEN", $AccessTokenSecureString)
351+
$galleryAz = Find-PSResource -Name AzPreview -Repository $Env:DEFAULT_PS_REPOSITORY_NAME -Credential $credentialsObject -TrustRepository
352+
}
353+
else {
354+
$galleryAz = Find-PSResource -Name AzPreview -Repository $GalleryName
355+
}
329356
$updatedModules = @()
330357
foreach ($localDependency in $localAz.RequiredModules)
331358
{

0 commit comments

Comments
 (0)