-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AzureFileCopy] Pick up latest Azure PowerShell module on Hosted agent #13067
Changes from 9 commits
2ba6fe1
a5f6d8e
0fcc34e
aca7a8e
c687ef6
4c28e57
4d43f41
043d388
da8766b
64438f1
ce0ddd4
c7b3c0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 167, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the minor version to the current sprint number. |
||
"Patch": 3 | ||
"Patch": 4 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 167, | ||
"Patch": 3 | ||
"Patch": 4 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ Import-Module $PSScriptRoot\ps_modules\RemoteDeployer | |
|
||
# Initialize Azure. | ||
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ | ||
$endpoint = Get-Endpoint -connectedServiceName $connectedServiceName | ||
Update-PSModulePathForHostedAgentWithLatestModule -Endpoint $endpoint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the line . "$PSScriptRoot\Utility.ps1" before the Get-Endpoint call |
||
Initialize-Azure | ||
|
||
# Import the loc strings. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 167, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the minor version to the current sprint number. |
||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 167, | ||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 3, | ||
"Minor": 167, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the minor version to the current sprint number. |
||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 3, | ||
"Minor": 167, | ||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 4, | ||
"Minor": 170, | ||
"Patch": 2 | ||
"Patch": 3 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"version": { | ||
"Major": 4, | ||
"Minor": 170, | ||
"Patch": 2 | ||
"Patch": 3 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 167, | ||
"Patch": 3 | ||
"Patch": 4 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
"version": { | ||
"Major": 2, | ||
"Minor": 167, | ||
"Patch": 3 | ||
"Patch": 4 | ||
}, | ||
"demands": [ | ||
"azureps" | ||
|
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." | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra line |
||
} | ||
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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 167, | ||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [ | ||
"sqlpackage" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
"version": { | ||
"Major": 1, | ||
"Minor": 167, | ||
"Patch": 4 | ||
"Patch": 5 | ||
}, | ||
"demands": [ | ||
"sqlpackage" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we currently fixing this for AzureCloudPowerShellDeployment task as well ?