Added support for running the agent behind a web proxy (--proxyurl) for both the PS module and the DSC resource

This commit is contained in:
psdgal 2022-02-24 08:10:19 +01:00 коммит произвёл Gallinari
Родитель cfc0376933
Коммит df86a701f2
2 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -131,6 +131,10 @@ function Set-TargetResource {
[System.String] [System.String]
$Work, $Work,
[parameter(Mandatory = $false)]
[System.String]
[string]$ProxyUrl,
[parameter(Mandatory = $true)] [parameter(Mandatory = $true)]
[System.String] [System.String]
$ServerUrl, $ServerUrl,
@ -171,6 +175,7 @@ function Set-TargetResource {
if ( $Work ) { $installArgs['Work'] = $Work } if ( $Work ) { $installArgs['Work'] = $Work }
if ( $LogonCredential ) { $installArgs['LogonCredential'] = $LogonCredential } if ( $LogonCredential ) { $installArgs['LogonCredential'] = $LogonCredential }
if ( $ProxyUrl ) { $installArgs['ProxyUrl'] = $ProxyUrl }
Install-VSTSAgent @installArgs Install-VSTSAgent @installArgs
} }

Просмотреть файл

@ -111,7 +111,10 @@ function Find-VSTSAgent {
[switch]$Latest, [switch]$Latest,
[parameter(Mandatory = $false)] [parameter(Mandatory = $false)]
[string]$Platform [string]$Platform,
[parameter(Mandatory = $false)]
[string]$ProxyUrl
) )
if ( $Latest ) { if ( $Latest ) {
@ -243,6 +246,10 @@ function Install-VSTSAgent {
[parameter(Mandatory = $true)] [parameter(Mandatory = $true)]
[uri]$ServerUrl, [uri]$ServerUrl,
[parameter(Mandatory = $false)]
[ValidateScript({ $_ -match "http://\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}:\d{1,5}" })]
[string]$ProxyUrl,
[parameter(Mandatory = $false)] [parameter(Mandatory = $false)]
[switch]$Replace, [switch]$Replace,
@ -271,6 +278,7 @@ function Install-VSTSAgent {
if ( $MinimumVersion ) { $findArgs['MinimumVersion'] = $MinimumVersion } if ( $MinimumVersion ) { $findArgs['MinimumVersion'] = $MinimumVersion }
if ( $MaximumVersion ) { $findArgs['MaximumVersion'] = $MaximumVersion } if ( $MaximumVersion ) { $findArgs['MaximumVersion'] = $MaximumVersion }
if ( $RequiredVersion ) { $findArgs['RequiredVersion'] = $RequiredVersion } if ( $RequiredVersion ) { $findArgs['RequiredVersion'] = $RequiredVersion }
if ( $ProxyUrl ) { $findArgs['ProxyUrl'] = $ProxyUrl }
$agent = Find-VSTSAgent @findArgs | Sort-Object -Descending -Property Version | Select-Object -First 1 $agent = Find-VSTSAgent @findArgs | Sort-Object -Descending -Property Version | Select-Object -First 1
if ( -not $agent ) { throw "Could not find agent matching requirements." } if ( -not $agent ) { throw "Could not find agent matching requirements." }
@ -319,6 +327,7 @@ function Install-VSTSAgent {
if ( $Replace ) { $configArgs += '--replace' } if ( $Replace ) { $configArgs += '--replace' }
if ( $LogonCredential ) { $configArgs += '--windowsLogonAccount', $LogonCredential.UserName } if ( $LogonCredential ) { $configArgs += '--windowsLogonAccount', $LogonCredential.UserName }
if ( $ProxyUrl ) { $configArgs += '--proxyurl', $ProxyUrl }
if ( $Work ) { $configArgs += '--work', $Work } if ( $Work ) { $configArgs += '--work', $Work }
if ( -not $PSCmdlet.ShouldProcess("$configPath $configArgs", "Start-Process") ) { return } if ( -not $PSCmdlet.ShouldProcess("$configPath $configArgs", "Start-Process") ) { return }