@@ -473,22 +473,38 @@ function Save-PackageLocally {
473473 $ModuleName = $module [' ModuleName' ]
474474 $RequiredVersion = $module [' RequiredVersion' ]
475475
476+ $AccessTokenSecureString = $env: SYSTEM_ACCESS_TOKEN | ConvertTo-SecureString - AsPlainText - Force
477+ $credentialsObject = [pscredential ]::new(" ONEBRANCH_TOKEN" , $AccessTokenSecureString )
478+
479+
476480 # Only check for the modules that specifies = required exact dependency version
477481 if ($RequiredVersion -ne $null ) {
478482 Write-Output " Checking for required module $ModuleName , $RequiredVersion "
479483 if (Find-Module - Name $ModuleName - RequiredVersion $RequiredVersion - Repository $TempRepo - ErrorAction SilentlyContinue) {
480484 Write-Output " Required dependency $ModuleName , $RequiredVersion found in the repo $TempRepo "
481485 } 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+ }
482494 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+ }
487503 $NupkgFilePath = Join-Path - Path $TempRepoPath - ChildPath " $ModuleName .$RequiredVersion .nupkg"
488504 $ModulePaths = $env: PSModulePath -split ' ;'
489505 $DestinationModulePath = [System.IO.Path ]::Combine($ModulePaths [0 ], $ModuleName , $RequiredVersion )
490506 Expand-Archive - Path $NupkgFilePath - DestinationPath $DestinationModulePath - Force
491- Write-Output " Downloaded the package sucessfully "
507+ Write-Output " Downloaded the package successfully "
492508 }
493509 }
494510}
@@ -583,7 +599,6 @@ function Add-AllModules {
583599 foreach ($module in $Keys ) {
584600 $modulePath = $Modules [$module ]
585601 Write-Output " Adding $module modules to local repo"
586-
587602 # Save missing dependencies locally from PS gallery.
588603 Save-PackagesFromPsGallery - TempRepo $TempRepo - TempRepoPath $TempRepoPath - ModulePaths $modulePath
589604
0 commit comments