[BUG]: GoTool@0 sets GOROOT for subsequent steps, but shouldn't #20796
Description
New issue checklist
- I searched for existing GitHub issues
- I read pipeline troubleshooting guide
- I checked how to collect logs
Task name
GoTool@0
Task version
0.246.3
Issue Description
The task sets GOROOT:
##[debug]Go tool is cached under /Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]set GOROOT=/Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]Processed: ##vso[task.setvariable variable=GOROOT;isOutput=false;issecret=false;]/Users/runner/hostedtoolcache/go/1.23.3/x64
This is not expected when using modern versions of Go. The GitHub Actions task has it right:
// Go versions less than 1.9 require GOROOT to be set
if (semver.lt(version, '1.9.0')) {
core.info('Setting GOROOT for Go version < 1.9');
core.exportVariable('GOROOT', installDir);
}
This repo appears to set it unconditionally:
azure-pipelines-tasks/Tasks/GoToolV0/gotool.ts
Lines 107 to 110 in a5d47e2
Originally I thought this was an issue with the agent and filed an issue, but now I've realized the issue is this setup task:
The reason it's not just unnecessary but potentially harmful to set GOROOT is menitoned in actions/runner-images#2655 and actions/runner-images#11331:
The problem with hardcoding a
GOROOT
is that if any other go tool is in use (for example, because one compiled Go tip), the environment variable will override its autodetectedGOROOT
. The result is that theGOROOT
and the go binary will mismatch, leading to obscure errors.
Specific example: when we try to call the Go tip's go tool dist test
, Go complains that "dist" doesn't exist, because it's looking in the wrong GOROOT. dist
doesn't exist for the preinstalled Go, but it does exist in the just-compiled Go tip.
As a workaround, explicitly unsetting GOROOT in our CI that uses this setup task fixes go tool dist test
for a Go tip build.
Environment type (Please select at least one enviroment where you face this issue)
- Self-Hosted
- Microsoft Hosted
- VMSS Pool
- Container
Azure DevOps Server type
dev.azure.com (formerly visualstudio.com)
Azure DevOps Server Version (if applicable)
No response
Operation system
macOS
Relevant log output
##[debug]Go tool is cached under /Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]set GOROOT=/Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]Processed: ##vso[task.setvariable variable=GOROOT;isOutput=false;issecret=false;]/Users/runner/hostedtoolcache/go/1.23.3/x64
Full task logs with system.debug enabled
No response