@@ -473,22 +473,38 @@ function Save-PackageLocally {
473
473
$ModuleName = $module [' ModuleName' ]
474
474
$RequiredVersion = $module [' RequiredVersion' ]
475
475
476
+ $AccessTokenSecureString = $env: SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString - AsPlainText - Force
477
+ $credentialsObject = [pscredential ]::new(" ONEBRANCH_TOKEN" , $AccessTokenSecureString )
478
+
479
+
476
480
# Only check for the modules that specifies = required exact dependency version
477
481
if ($RequiredVersion -ne $null ) {
478
482
Write-Output " Checking for required module $ModuleName , $RequiredVersion "
479
483
if (Find-Module - Name $ModuleName - RequiredVersion $RequiredVersion - Repository $TempRepo - ErrorAction SilentlyContinue) {
480
484
Write-Output " Required dependency $ModuleName , $RequiredVersion found in the repo $TempRepo "
481
485
} else {
486
+ if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
487
+ $PSRepositoryUrl = $Env: DEFAULT_PS_REPOSITORY_URL
488
+ $AccessTokenSecureString = $env: SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString - AsPlainText - Force
489
+ $credentialsObject = [pscredential ]::new(" ONEBRANCH_TOKEN" , $AccessTokenSecureString )
490
+ }
491
+ else {
492
+ $PSRepositoryUrl = " https://www.powershellgallery.com/api/v2"
493
+ }
482
494
Write-Warning " Required dependency $ModuleName , $RequiredVersion not found in the repo $TempRepo "
483
- Write-Output " Downloading the package from PsGallery to the path $TempRepoPath "
484
- # We try to download the package from the PsGallery as we are likely intending to use the existing version of the module.
485
- # If the module not found in psgallery, the following commnad would fail and hence publish to local repo process would fail as well
486
- Save-Package - Name $ModuleName - RequiredVersion $RequiredVersion - ProviderName Nuget - Path $TempRepoPath - Source https:// www.powershellgallery.com / api/ v2 | Out-Null
495
+ Write-Output " Downloading the package from $PSRepositoryUrl to the path $TempRepoPath "
496
+ # We try to download the package from the PSRepositoryUrl as we are likely intending to use the existing version of the module.
497
+ # If the module not found in PSRepositoryUrl, the following command would fail and hence publish to local repo process would fail as well
498
+ if (Test-Path Env:\DEFAULT_PS_REPOSITORY_URL) {
499
+ Save-PSResource - Name $ModuleName - Version $RequiredVersion - Path $TempRepoPath - Repository $Env: DEFAULT_PS_REPOSITORY_NAME - Credential $credentialsObject - AsNupkg
500
+ } else {
501
+ Save-PSResource - Name $ModuleName - Version $RequiredVersion - Path $TempRepoPath - Repository PSGallery - AsNupkg
502
+ }
487
503
$NupkgFilePath = Join-Path - Path $TempRepoPath - ChildPath " $ModuleName .$RequiredVersion .nupkg"
488
504
$ModulePaths = $env: PSModulePath -split ' ;'
489
505
$DestinationModulePath = [System.IO.Path ]::Combine($ModulePaths [0 ], $ModuleName , $RequiredVersion )
490
506
Expand-Archive - Path $NupkgFilePath - DestinationPath $DestinationModulePath - Force
491
- Write-Output " Downloaded the package sucessfully "
507
+ Write-Output " Downloaded the package successfully "
492
508
}
493
509
}
494
510
}
@@ -583,7 +599,6 @@ function Add-AllModules {
583
599
foreach ($module in $Keys ) {
584
600
$modulePath = $Modules [$module ]
585
601
Write-Output " Adding $module modules to local repo"
586
-
587
602
# Save missing dependencies locally from PS gallery.
588
603
Save-PackagesFromPsGallery - TempRepo $TempRepo - TempRepoPath $TempRepoPath - ModulePaths $modulePath
589
604
0 commit comments