From df86a701f26357a4b2d538b9e535713711c6a5bd Mon Sep 17 00:00:00 2001 From: psdgal Date: Thu, 24 Feb 2022 08:10:19 +0100 Subject: [PATCH] Added support for running the agent behind a web proxy (--proxyurl) for both the PS module and the DSC resource --- VSTSAgent/DSCResources/xVSTSAgent/xVSTSAgent.psm1 | 5 +++++ VSTSAgent/VSTSAgent.psm1 | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/VSTSAgent/DSCResources/xVSTSAgent/xVSTSAgent.psm1 b/VSTSAgent/DSCResources/xVSTSAgent/xVSTSAgent.psm1 index f2e135e..56ef5e5 100644 --- a/VSTSAgent/DSCResources/xVSTSAgent/xVSTSAgent.psm1 +++ b/VSTSAgent/DSCResources/xVSTSAgent/xVSTSAgent.psm1 @@ -131,6 +131,10 @@ function Set-TargetResource { [System.String] $Work, + [parameter(Mandatory = $false)] + [System.String] + [string]$ProxyUrl, + [parameter(Mandatory = $true)] [System.String] $ServerUrl, @@ -171,6 +175,7 @@ function Set-TargetResource { if ( $Work ) { $installArgs['Work'] = $Work } if ( $LogonCredential ) { $installArgs['LogonCredential'] = $LogonCredential } + if ( $ProxyUrl ) { $installArgs['ProxyUrl'] = $ProxyUrl } Install-VSTSAgent @installArgs } diff --git a/VSTSAgent/VSTSAgent.psm1 b/VSTSAgent/VSTSAgent.psm1 index d5a09f9..9ffe4d6 100644 --- a/VSTSAgent/VSTSAgent.psm1 +++ b/VSTSAgent/VSTSAgent.psm1 @@ -111,7 +111,10 @@ function Find-VSTSAgent { [switch]$Latest, [parameter(Mandatory = $false)] - [string]$Platform + [string]$Platform, + + [parameter(Mandatory = $false)] + [string]$ProxyUrl ) if ( $Latest ) { @@ -243,6 +246,10 @@ function Install-VSTSAgent { [parameter(Mandatory = $true)] [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)] [switch]$Replace, @@ -271,6 +278,7 @@ function Install-VSTSAgent { if ( $MinimumVersion ) { $findArgs['MinimumVersion'] = $MinimumVersion } if ( $MaximumVersion ) { $findArgs['MaximumVersion'] = $MaximumVersion } if ( $RequiredVersion ) { $findArgs['RequiredVersion'] = $RequiredVersion } + if ( $ProxyUrl ) { $findArgs['ProxyUrl'] = $ProxyUrl } $agent = Find-VSTSAgent @findArgs | Sort-Object -Descending -Property Version | Select-Object -First 1 if ( -not $agent ) { throw "Could not find agent matching requirements." } @@ -319,6 +327,7 @@ function Install-VSTSAgent { if ( $Replace ) { $configArgs += '--replace' } if ( $LogonCredential ) { $configArgs += '--windowsLogonAccount', $LogonCredential.UserName } + if ( $ProxyUrl ) { $configArgs += '--proxyurl', $ProxyUrl } if ( $Work ) { $configArgs += '--work', $Work } if ( -not $PSCmdlet.ShouldProcess("$configPath $configArgs", "Start-Process") ) { return }