Skip to content
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

Allow specification of Azure Dev Ops Server (On-Prem) URL #834

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Artifacts/windows-vsts-build-agent/Artifactfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
{
Expand Down
39 changes: 31 additions & 8 deletions Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -135,7 +156,7 @@ function Get-AgentPackage
{
[CmdletBinding()]
param(
[string] $VstsAccount,
[string] $VstsUrl,
[string] $VstsUserPassword
)

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -413,7 +436,7 @@ try
PoolName = $poolName
ReplaceAgent = $replaceAgent
RunAsAutoLogon = $runAsAutoLogon
ServerUrl = "https://$VstsAccount.visualstudio.com"
ServerUrl = $vstsUrlFull
VstsUserPassword = $vstsUserPassword
WindowsLogonAccount = $windowsLogonAccount
WindowsLogonPassword = $windowsLogonPassword
Expand Down