From dc4d80eda95b6ff3a892c92ba949c162bce4442c Mon Sep 17 00:00:00 2001 From: tgillitzer Date: Thu, 14 Apr 2022 12:15:00 -0500 Subject: [PATCH 1/8] Update script to allow specification of VSTS URL --- .../vsts-agent-install.ps1 | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 b/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 index edbebb99b..78836ea92 100644 --- a/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 +++ b/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 @@ -2,6 +2,7 @@ # Studio Online account, and adds to the specified build agent pool [CmdletBinding()] param( + [string] $vstsUrl, [string] $vstsAccount, [string] $vstsUserPassword, [string] $agentName, @@ -80,6 +81,7 @@ function Test-Parameters { [CmdletBinding()] param( + [string] $VstsUrl, [string] $VstsAccount, [string] $WorkDirectory ) @@ -93,6 +95,35 @@ function Test-Parameters { throw "Work directory '$WorkDirectory' is not a valid path." } + + if ($VstsUrl) + { + $serverUrl = $VstsUrl + } + else + { + $serverUrl = "https://$VstsAccount.visualstudio.com" + } +} + +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 @@ -135,7 +166,7 @@ function Get-AgentPackage { [CmdletBinding()] param( - [string] $VstsAccount, + [string] $VstsUrl, [string] $VstsUserPassword ) @@ -144,8 +175,8 @@ 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 +416,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 @@ -395,7 +429,7 @@ try } Write-Host 'Downloading agent package' - $agentPackagePath = Get-AgentPackage -VstsAccount $vstsAccount -VstsUserPassword $vstsUserPassword + $agentPackagePath = Get-AgentPackage -VstsUrl $vstsUrlFull -VstsUserPassword $vstsUserPassword Write-Host 'Extracting agent package contents' Extract-AgentPackage -PackagePath $agentPackagePath -Destination $agentInstallPath @@ -413,7 +447,7 @@ try PoolName = $poolName ReplaceAgent = $replaceAgent RunAsAutoLogon = $runAsAutoLogon - ServerUrl = "https://$VstsAccount.visualstudio.com" + ServerUrl = $vstsUrlFull VstsUserPassword = $vstsUserPassword WindowsLogonAccount = $windowsLogonAccount WindowsLogonPassword = $windowsLogonPassword From 73ab75c43304de4ebc852ce1cd7bd2e03022c901 Mon Sep 17 00:00:00 2001 From: tgillitzer Date: Thu, 14 Apr 2022 12:17:51 -0500 Subject: [PATCH 2/8] Add Azure DevOps URL --- Artifacts/windows-vsts-build-agent/Artifactfile.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index cc98d8702..2a9cc3163 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", From ff13fac532c3284da51d3f7fa31b0487a829521e Mon Sep 17 00:00:00 2001 From: tgillitzer Date: Thu, 14 Apr 2022 16:41:49 -0500 Subject: [PATCH 3/8] Fix vstsUserPassword parameter name --- Artifacts/windows-vsts-build-agent/Artifactfile.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index 2a9cc3163..281148c68 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -22,7 +22,7 @@ "displayName": "Azure DevOps Organization Name", "description": "The name of the Azure DevOps organization to add the agent to. This is the value in your Azure DevOps URL: e.g. 'myorg' in https://dev.azure.com/myorg." }, - "vstsPassword": { + "vstsUserPassword": { "type": "securestring", "displayName": "Azure DevOps Personal Access Token", "description": "A personal access token with permissions to add agents. It will only be used to register the agent." From d2d10db8ce3acccecdb7bee6b2d8b03df3ebc196 Mon Sep 17 00:00:00 2001 From: tgillitzer Date: Thu, 14 Apr 2022 16:41:49 -0500 Subject: [PATCH 4/8] Revert "Fix vstsUserPassword parameter name" This reverts commit ff13fac532c3284da51d3f7fa31b0487a829521e. --- Artifacts/windows-vsts-build-agent/Artifactfile.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index 281148c68..2a9cc3163 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -22,7 +22,7 @@ "displayName": "Azure DevOps Organization Name", "description": "The name of the Azure DevOps organization to add the agent to. This is the value in your Azure DevOps URL: e.g. 'myorg' in https://dev.azure.com/myorg." }, - "vstsUserPassword": { + "vstsPassword": { "type": "securestring", "displayName": "Azure DevOps Personal Access Token", "description": "A personal access token with permissions to add agents. It will only be used to register the agent." From a8789f2cdedcfd8ba4f7596aa5e81bd10d9c8622 Mon Sep 17 00:00:00 2001 From: Travis Gillitzer Date: Thu, 14 Apr 2022 16:52:41 -0500 Subject: [PATCH 5/8] add parameter to command --- .../Artifactfile.json | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index 2a9cc3163..aadd8e115 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -3,12 +3,7 @@ "title": "Azure Pipelines Agent", "publisher": "Microsoft", "description": "Downloads and installs the Azure Pipelines agent, registers with the specified Azure DevOps Services account, and adds the VM to the specified agent pool.", - "tags": [ - "VSTS", - "Build", - "CI", - "Windows" - ], + "tags": ["VSTS", "Build", "CI", "Windows"], "iconUri": "https://cdn.vsassets.io/content/icons/favicon.ico", "targetOsType": "Windows", "parameters": { @@ -71,7 +66,30 @@ "maxLength": 1, "minLength": 1, "allowedValues": [ - "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" + "C", + "D", + "E", + "F", + "G", + "H", + "I", + "J", + "K", + "L", + "M", + "N", + "O", + "P", + "Q", + "R", + "S", + "T", + "U", + "V", + "W", + "X", + "Y", + "Z" ] }, "workDirectory": { @@ -89,7 +107,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', ' -vstsAccount ''', parameters('vstsUrl'), ''' -vstsUrl ''', 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": [ { From beba84e1be896f416d207dd675704015cf945b77 Mon Sep 17 00:00:00 2001 From: Travis Gillitzer Date: Thu, 14 Apr 2022 16:56:13 -0500 Subject: [PATCH 6/8] fix parameters in command --- Artifacts/windows-vsts-build-agent/Artifactfile.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index aadd8e115..904e33556 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -107,7 +107,7 @@ } }, "runCommand": { - "commandToExecute": "[concat('powershell.exe -ExecutionPolicy bypass \"& ./vsts-agent-install.ps1', ' -vstsAccount ''', parameters('vstsUrl'), ''' -vstsUrl ''', 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": [ { From 1c54a3477052fc05339e8871195c5df422fb80a9 Mon Sep 17 00:00:00 2001 From: Travis Gillitzer Date: Fri, 15 Apr 2022 09:17:02 -0500 Subject: [PATCH 7/8] A little cleanup --- .../Artifactfile.json | 34 ++++--------------- .../vsts-agent-install.ps1 | 17 ++-------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index 904e33556..f89b2979f 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -3,7 +3,12 @@ "title": "Azure Pipelines Agent", "publisher": "Microsoft", "description": "Downloads and installs the Azure Pipelines agent, registers with the specified Azure DevOps Services account, and adds the VM to the specified agent pool.", - "tags": ["VSTS", "Build", "CI", "Windows"], + "tags": [ + "VSTS", + "Build", + "CI", + "Windows" + ], "iconUri": "https://cdn.vsassets.io/content/icons/favicon.ico", "targetOsType": "Windows", "parameters": { @@ -65,32 +70,7 @@ "defaultValue": "C", "maxLength": 1, "minLength": 1, - "allowedValues": [ - "C", - "D", - "E", - "F", - "G", - "H", - "I", - "J", - "K", - "L", - "M", - "N", - "O", - "P", - "Q", - "R", - "S", - "T", - "U", - "V", - "W", - "X", - "Y", - "Z" - ] + "allowedValues": ["C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] }, "workDirectory": { "type": "string", diff --git a/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 b/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 index 78836ea92..d7fe4b9f3 100644 --- a/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 +++ b/Artifacts/windows-vsts-build-agent/vsts-agent-install.ps1 @@ -1,5 +1,5 @@ -# 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, @@ -81,7 +81,6 @@ function Test-Parameters { [CmdletBinding()] param( - [string] $VstsUrl, [string] $VstsAccount, [string] $WorkDirectory ) @@ -95,15 +94,6 @@ function Test-Parameters { throw "Work directory '$WorkDirectory' is not a valid path." } - - if ($VstsUrl) - { - $serverUrl = $VstsUrl - } - else - { - $serverUrl = "https://$VstsAccount.visualstudio.com" - } } function Set-ServerUrl @@ -175,7 +165,6 @@ function Get-AgentPackage New-Item -ItemType Directory -Force -Path $agentTempFolderName | Out-Null $agentPackagePath = "$agentTempFolderName\agent.zip" - $vstsAgentUrl = "$VstsUrl/_apis/distributedtask/packages/agent/win7-x64?`$top=1&api-version=3.0" $vstsUser = "AzureDevTestLabs" @@ -428,7 +417,7 @@ try Test-AgentExists -InstallPath $agentInstallPath -AgentName $agentName } - Write-Host 'Downloading agent package' + Write-Host "Downloading agent package from $vstsUrlFull" $agentPackagePath = Get-AgentPackage -VstsUrl $vstsUrlFull -VstsUserPassword $vstsUserPassword Write-Host 'Extracting agent package contents' From ab8576aab8537fd03e2dd19d16d7079a14633e81 Mon Sep 17 00:00:00 2001 From: Travis Gillitzer Date: Fri, 15 Apr 2022 09:18:04 -0500 Subject: [PATCH 8/8] white space --- Artifacts/windows-vsts-build-agent/Artifactfile.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Artifacts/windows-vsts-build-agent/Artifactfile.json b/Artifacts/windows-vsts-build-agent/Artifactfile.json index f89b2979f..608dcbef3 100644 --- a/Artifacts/windows-vsts-build-agent/Artifactfile.json +++ b/Artifacts/windows-vsts-build-agent/Artifactfile.json @@ -70,7 +70,9 @@ "defaultValue": "C", "maxLength": 1, "minLength": 1, - "allowedValues": ["C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] + "allowedValues": [ + "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" + ] }, "workDirectory": { "type": "string",