-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AzureFileCopy] Pick up latest Azure PowerShell module on Hosted agent (
#13067) * update azure file copy to use latest available azure rm module on hosted agent environment * update task version * check for null for latestazurermmodulepath * move psmoduleutility to common. afcv2 and afcv3 * refactor out get-endpointauthenticationscheme function * use endpoint.type instead of authentication scheme to check whether or not to update env:psmodulepath * update task version of tasks using common modules dependency * remove endpoint utility as it is not needed * load utility.ps1 before calling get-endpoint * update minor version Co-authored-by: Ashish Ranjan 💩 <asranja@microsoft.com>
- Loading branch information
Showing
24 changed files
with
137 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
function Update-PSModulePathForHostedAgentWithLatestModule | ||
{ | ||
[CmdletBinding()] | ||
param( | ||
[object] $Endpoint | ||
) | ||
|
||
Trace-VstsEnteringInvocation $MyInvocation | ||
try | ||
{ | ||
$authenticationScheme = $Endpoint.Auth.Scheme | ||
|
||
if ($authenticationScheme -eq "ServicePrincipal" -or | ||
$authenticationScheme -eq "ManagedServiceIdentity") | ||
{ | ||
Write-Verbose "Updating PSModulePath with latest AzureRM module." | ||
$latestAzureRmModulePath = Get-LatestAzureRmModulePath | ||
|
||
if (![string]::IsNullOrEmpty($latestAzureRmModulePath)) | ||
{ | ||
$env:PSModulePath = "$latestAzureRmModulePath;$env:PSModulePath" | ||
} | ||
else | ||
{ | ||
Write-Verbose "Latest AzureRM module path is null or empty." | ||
} | ||
} | ||
|
||
} | ||
finally | ||
{ | ||
Write-Verbose "The updated value of the PSModulePath is: $($env:PSModulePath)" | ||
Trace-VstsLeavingInvocation $MyInvocation | ||
} | ||
} | ||
|
||
function Get-LatestAzureRmModulePath | ||
{ | ||
[CmdletBinding()] | ||
param() | ||
|
||
Trace-VstsEnteringInvocation $MyInvocation | ||
$hostedAgentAzureModulesPath = Join-Path -Path $env:SystemDrive -ChildPath "modules" | ||
$latestAzureRmModulePath = "" | ||
try | ||
{ | ||
if ($(Test-Path $hostedAgentAzureModulesPath)) | ||
{ | ||
$regexToMatch = New-Object -TypeName System.Text.RegularExpressions.Regex -ArgumentList "^azurerm_[0-9]+\.[0-9]+\.[0-9]+$" | ||
$regexToExtract = New-Object -TypeName System.Text.RegularExpressions.Regex -ArgumentList "[0-9]+\.[0-9]+\.[0-9]+$" | ||
$maxVersion = [version] "0.0.0" | ||
|
||
$moduleFolders = Get-ChildItem -Directory -Path $hostedAgentAzureModulesPath | Where-Object { $regexToMatch.IsMatch($_.Name) } | ||
|
||
foreach ($moduleFolder in $moduleFolders) | ||
{ | ||
$moduleVersion = [version] $($regexToExtract.Match($moduleFolder.Name).Groups[0].Value) | ||
|
||
if ($moduleVersion -gt $maxVersion) | ||
{ | ||
$modulePath = [System.IO.Path]::Combine($moduleFolder.FullName,"AzureRM\$moduleVersion\AzureRM.psm1") | ||
|
||
if (Test-Path -LiteralPath $modulePath -PathType Leaf) | ||
{ | ||
$maxVersion = $moduleVersion | ||
$latestAzureRmModulePath = $moduleFolder.FullName | ||
} | ||
else | ||
{ | ||
Write-Verbose "A folder matching the module folder pattern was found at $($moduleFolder.FullName) but didn't contain a valid module file" | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Write-Verbose "Hosted Agent Azure modules path '$hostedAgentAzureModulesPath' does not exist." | ||
} | ||
|
||
return $latestAzureRmModulePath | ||
} | ||
catch | ||
{ | ||
Write-Verbose "Get-LatestAzureRmModulePath: Exception: $($_.Exception.Message)" | ||
$latestAzureRmModulePath = "" | ||
} | ||
finally | ||
{ | ||
Trace-VstsLeavingInvocation $MyInvocation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters