From 902346ebcd3a34c98023db2282e11003f71ca5bf Mon Sep 17 00:00:00 2001 From: Ryan Spletzer Date: Tue, 9 Feb 2021 08:41:06 -0500 Subject: [PATCH] Set AGENT_TOOLSDIRECTORY in packer template (#2457) * Set AGENT_TOOLSDIRECTORY in packer template This was set in the ruby installer but it is referenced elsewhere so I believe it makes the most sense to have this set centrally in the packer template to be referenced across multiple scripts. * Fix typo * Capitalize env var in ws2016 template for consistency * Set AGENT_TOOLSDIRECTORY in Initialize-VM.ps1 * Add missing env var for AGENT_TOOLSDIRECTORY in step in ws2016 template --- images/win/scripts/Installers/Initialize-VM.ps1 | 1 + images/win/scripts/Installers/Install-Ruby.ps1 | 5 ----- images/win/windows2016.json | 2 ++ images/win/windows2019.json | 2 ++ 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/images/win/scripts/Installers/Initialize-VM.ps1 b/images/win/scripts/Installers/Initialize-VM.ps1 index 26ce2a4e..7623497e 100644 --- a/images/win/scripts/Installers/Initialize-VM.ps1 +++ b/images/win/scripts/Installers/Initialize-VM.ps1 @@ -36,6 +36,7 @@ Add-Content -Path $profile.AllUsersAllHosts -Value '$ErrorActionPreference="Stop # Set static env vars setx ImageVersion $env:IMAGE_VERSION /m setx ImageOS $env:IMAGE_OS /m +setx AGENT_TOOLSDIRECTORY $env:AGENT_TOOLSDIRECTORY /m # Set TLS1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor "Tls12" diff --git a/images/win/scripts/Installers/Install-Ruby.ps1 b/images/win/scripts/Installers/Install-Ruby.ps1 index 6398bf09..ef0436ae 100644 --- a/images/win/scripts/Installers/Install-Ruby.ps1 +++ b/images/win/scripts/Installers/Install-Ruby.ps1 @@ -98,11 +98,6 @@ function Set-DefaultRubyVersion Add-MachinePathItem -PathItem $rubyDir | Out-Null } -# Define AGENT_TOOLSDIRECTORY environment variable -$toolsDirectory = "C:/hostedtoolcache/windows" -$env:AGENT_TOOLSDIRECTORY = $toolsDirectory -setx AGENT_TOOLSDIRECTORY $toolsDirectory /M - # Install Ruby $rubyTools = (Get-ToolsetContent).toolcache | Where-Object { $_.name -eq "Ruby" } $rubyToolVersions = $rubyTools.versions diff --git a/images/win/windows2016.json b/images/win/windows2016.json index 98484d2c..ad4876dd 100644 --- a/images/win/windows2016.json +++ b/images/win/windows2016.json @@ -21,6 +21,7 @@ "imagedata_file": "C:\\imagedata.json", "helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\", "psmodules_root_folder": "C:\\Modules", + "agent_tools_directory": "C:\\hostedtoolcache\\windows", "install_user": "installer", "install_password": null, "capture_name_prefix": "packer", @@ -114,6 +115,7 @@ "environment_vars": [ "IMAGE_VERSION={{user `image_version`}}", "IMAGE_OS={{user `image_os`}}", + "AGENT_TOOLSDIRECTORY={{user `agent_tools_directory`}}", "TOOLSET_JSON_PATH={{user `toolset_json_path`}}", "PSMODULES_ROOT_FOLDER={{user `psmodules_root_folder`}}" ], diff --git a/images/win/windows2019.json b/images/win/windows2019.json index 7c48cb86..268bcce0 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -21,6 +21,7 @@ "imagedata_file": "C:\\imagedata.json", "helper_script_folder": "C:\\Program Files\\WindowsPowerShell\\Modules\\", "psmodules_root_folder": "C:\\Modules", + "agent_tools_directory": "C:\\hostedtoolcache\\windows", "install_user": "installer", "install_password": null, "capture_name_prefix": "packer", @@ -114,6 +115,7 @@ "environment_vars": [ "IMAGE_VERSION={{user `image_version`}}", "IMAGE_OS={{user `image_os`}}", + "AGENT_TOOLSDIRECTORY={{user `agent_tools_directory`}}", "TOOLSET_JSON_PATH={{user `toolset_json_path`}}", "PSMODULES_ROOT_FOLDER={{user `psmodules_root_folder`}}" ],