diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index cc98d8702..608dcbef3 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -12,6 +12,11 @@ "iconUri": "https://cdn.vsassets.io/content/icons/favicon.ico", "targetOsType": "Windows", "parameters": { + "vstsUrl": { + "type": "string", + "displayName": "Azure DevOps URL", + "description": "The URL of the Azure DevOps Server. If this is not specified, then Azure DevOps Services is assumed." + }, "vstsAccount": { "type": "string", "displayName": "Azure DevOps Organization Name", @@ -84,7 +89,7 @@ } }, "runCommand": { - "commandToExecute": "[concat('powershell.exe -ExecutionPolicy bypass \"& ./vsts-agent-install.ps1', ' -vstsAccount ''', parameters('vstsAccount'), ''' -vstsUserPassword ', parameters('vstsPassword'), ' -agentName ''', parameters('agentName'), ''' -agentNameSuffix ''', parameters('agentNameSuffix'), ''' -poolName ''', parameters('poolName'), ''' -runAsAutoLogon $', parameters('runAsAutoLogon') , ' -windowsLogonAccount ''', parameters('windowsLogonAccount'), ''' -windowsLogonPassword ''', parameters('windowsLogonPassword'), ''' -driveLetter ', parameters('driveLetter'), ' -workDirectory ''', parameters('workDirectory'), ''' -replaceAgent $', parameters('replaceAgent') , '\"')]" + "commandToExecute": "[concat('powershell.exe -ExecutionPolicy bypass \"& ./vsts-agent-install.ps1', ' -vstsUrl ''', parameters('vstsUrl'), ''' -vstsAccount ''', parameters('vstsAccount'), ''' -vstsUserPassword ', parameters('vstsPassword'), ' -agentName ''', parameters('agentName'), ''' -agentNameSuffix ''', parameters('agentNameSuffix'), ''' -poolName ''', parameters('poolName'), ''' -runAsAutoLogon $', parameters('runAsAutoLogon') , ' -windowsLogonAccount ''', parameters('windowsLogonAccount'), ''' -windowsLogonPassword ''', parameters('windowsLogonPassword'), ''' -driveLetter ', parameters('driveLetter'), ' -workDirectory ''', parameters('workDirectory'), ''' -replaceAgent $', parameters('replaceAgent') , '\"')]" }, "postDeployActions": [ { diff --git a/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 b/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 index edbebb99b..d7fe4b9f3 100644 --- a/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 +++ b/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 @@ -1,7 +1,8 @@ -# Downloads the Visual Studio Online Build Agent, installs on the new machine, registers with the Visual -# Studio Online account, and adds to the specified build agent pool +# Downloads the Azure Dev Ops Pipeline Agent, installs on the new machine, +# registers with Azure Dev Ops, and adds to the specified build agent pool [CmdletBinding()] param( + [string] $vstsUrl, [string] $vstsAccount, [string] $vstsUserPassword, [string] $agentName, @@ -95,6 +96,26 @@ function Test-Parameters } } +function Set-ServerUrl +{ + [CmdletBinding()] + param( + [string] $VstsUrl, + [string] $VstsAccount + ) + + if ($VstsUrl) + { + $serverUrl = "$VstsUrl/$VstsAccount" + } + else + { + $serverUrl = "https://$VstsAccount.visualstudio.com" + } + + return $serverUrl +} + function Test-ValidPath { param( @@ -135,7 +156,7 @@ function Get-AgentPackage { [CmdletBinding()] param( - [string] $VstsAccount, + [string] $VstsUrl, [string] $VstsUserPassword ) @@ -144,8 +165,7 @@ function Get-AgentPackage New-Item -ItemType Directory -Force -Path $agentTempFolderName | Out-Null $agentPackagePath = "$agentTempFolderName\agent.zip" - $serverUrl = "https://$VstsAccount.visualstudio.com" - $vstsAgentUrl = "$serverUrl/_apis/distributedtask/packages/agent/win7-x64?`$top=1&api-version=3.0" + $vstsAgentUrl = "$VstsUrl/_apis/distributedtask/packages/agent/win7-x64?`$top=1&api-version=3.0" $vstsUser = "AzureDevTestLabs" $maxRetries = 3 @@ -385,6 +405,9 @@ try Write-Host 'Validating parameters' Test-Parameters -VstsAccount $vstsAccount -WorkDirectory $workDirectory + Write-Host 'Setting ServerUrl' + $vstsUrlFull = Set-ServerUrl -VstsUrl $vstsUrl -VstsAccount $vstsAccount + Write-Host 'Preparing agent installation location' $agentInstallPath = New-AgentInstallPath -DriveLetter $driveLetter -AgentName $agentName @@ -394,8 +417,8 @@ try Test-AgentExists -InstallPath $agentInstallPath -AgentName $agentName } - Write-Host 'Downloading agent package' - $agentPackagePath = Get-AgentPackage -VstsAccount $vstsAccount -VstsUserPassword $vstsUserPassword + Write-Host "Downloading agent package from $vstsUrlFull" + $agentPackagePath = Get-AgentPackage -VstsUrl $vstsUrlFull -VstsUserPassword $vstsUserPassword Write-Host 'Extracting agent package contents' Extract-AgentPackage -PackagePath $agentPackagePath -Destination $agentInstallPath @@ -413,7 +436,7 @@ try PoolName = $poolName ReplaceAgent = $replaceAgent RunAsAutoLogon = $runAsAutoLogon - ServerUrl = "https://$VstsAccount.visualstudio.com" + ServerUrl = $vstsUrlFull VstsUserPassword = $vstsUserPassword WindowsLogonAccount = $windowsLogonAccount WindowsLogonPassword = $windowsLogonPassword