If chocolatey is installed as non-admin, the main task will throw an exception while trying to find it.
Expected Behavior
With Chocolatey not installed, the Azure DevOps task reports the error
With Chocolatey installed as user rather than machine, the Azure DevOps task can find it
Current Behavior
With no Chocolatey install:
2020-09-15T07:26:17.8551816Z ==============================================================================
2020-09-15T07:26:17.8551998Z Task : Chocolatey
2020-09-15T07:26:17.8552170Z Description : Run various Chocolatey commands, including pack, push, install, upgrade, etc.
2020-09-15T07:26:17.8552325Z Version : 0.3.2
2020-09-15T07:26:17.8552435Z Author : gep13
2020-09-15T07:26:17.8552616Z Help : [More Information](https://chocolatey-community.github.io/chocolatey-azuredevops/
2020-09-15T07:26:17.8552817Z ==============================================================================
2020-09-15T07:26:18.4250477Z ##[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
2020-09-15T07:26:18.5267096Z ##[debug]Entering C:\AzureDevopsAgent\_work\_tasks\ChocolateyCommand_7360ca82-d88f-4188-be8f-88d60ca03f4f\0.3.2\chocolatey.ps1.
2020-09-15T07:26:18.5544508Z ##[error]Cannot bind argument to parameter 'Path' because it is null.
2020-09-15T07:26:18.5550697Z ##[debug]Processed: ##vso[task.logissue type=error]Cannot bind argument to parameter 'Path' because it is null.
2020-09-15T07:26:18.5551224Z ##[debug]Leaving C:\AzureDevopsAgent\_work\_tasks\ChocolateyCommand_7360ca82-d88f-4188-be8f-88d60ca03f4f\0.3.2\chocolatey.ps1.
2020-09-15T07:26:18.5578634Z ##[debug]Caught exception from task script.
2020-09-15T07:26:18.5598480Z ##[debug]Error record:
2020-09-15T07:26:18.6061369Z ##[debug]Test-Path : Cannot bind argument to parameter 'Path' because it is null.
2020-09-15T07:26:18.6069498Z ##[debug]At C:\AzureDevopsAgent\_work\_tasks\ChocolateyCommand_7360ca82-d88f-4188-be8f-88d60ca03f4f\0.3.2\chocolatey.ps1:8 char:21
2020-09-15T07:26:18.6077796Z ##[debug]+ if(-not (Test-Path $chocoInstallLocation)) {
2020-09-15T07:26:18.6086256Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~
2020-09-15T07:26:18.6094753Z ##[debug] + CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
2020-09-15T07:26:18.6103143Z ##[debug] + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCom mand
2020-09-15T07:26:18.6112114Z ##[debug]
2020-09-15T07:26:18.6125702Z ##[debug]Script stack trace:
2020-09-15T07:26:18.6150181Z ##[debug]at <ScriptBlock>, C:\AzureDevopsAgent\_work\_tasks\ChocolateyCommand_7360ca82-d88f-4188-be8f-88d60ca03f4f\0.3.2\chocolatey.ps1: line 8
2020-09-15T07:26:18.6157998Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-09-15T07:26:18.6166420Z ##[debug]at <ScriptBlock>, <No file>: line 22
2020-09-15T07:26:18.6174727Z ##[debug]at <ScriptBlock>, <No file>: line 18
2020-09-15T07:26:18.6183087Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-09-15T07:26:18.6196520Z ##[debug]Exception:
2020-09-15T07:26:18.6224353Z ##[debug]System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Path' because it is null.
2020-09-15T07:26:18.6232166Z ##[debug] at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
2020-09-15T07:26:18.6240426Z ##[debug] at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
2020-09-15T07:26:18.6248732Z ##[debug] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2020-09-15T07:26:18.6257092Z ##[debug] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
2020-09-15T07:26:18.6269715Z ##[error]Cannot bind argument to parameter 'Path' because it is null.
2020-09-15T07:26:18.6270351Z ##[debug]Processed: ##vso[task.logissue type=error]Cannot bind argument to parameter 'Path' because it is null.
2020-09-15T07:26:18.6279548Z ##[debug]Processed: ##vso[task.complete result=Failed]
2020-09-15T07:26:18.6885615Z ##[section]Finishing: ChocolateyCommand
With per user-install, probably the same error?
Possible Solution
Apply the same change to chocolatey.ps1 that was done to installer.ps1
Steps to Reproduce (for bugs)
Have an Azure DevOps agent with no chocolatey install
Observe the exception during build rather than the error message
The same should be true if the installer task is called first with the ChocolateyInstall environment variable set to perform a per-user install. I expect the main ChocolateyCommand will throw the exception rather than finding the per-user install.
Context
This was while trying to use chocolatey to install a package for out build pipeline which runs on a self-hosted agent.
It turns out that it's not a big problem for us because the package we were going to use Chocolatey to install has its own installer we can use anyway.
Your Environment
Azure Devops self-hosted build agent on a Windows 10 machine
When running the Chocolatey task on our self-hosted build agent, the powershell script for the tasks throws an exception. That exception has already been fixed in the installer (https://github.com/chocolatey-community/chocolatey-azuredevops/commit/5402d575ea2e9f36ae753eb770fe68e440703db5#diff-ae9d19e3da5eb0a33721214a238cf04a), but not in the main task script (https://github.com/chocolatey-community/chocolatey-azuredevops/blob/92b679475c8ebcf9215c64ed246f5a3b23783a20/Tasks/chocolatey/chocolatey.ps1#L8).
If chocolatey is installed as non-admin, the main task will throw an exception while trying to find it.
Expected Behavior
With Chocolatey not installed, the Azure DevOps task reports the error With Chocolatey installed as user rather than machine, the Azure DevOps task can find it
Current Behavior
With no Chocolatey install:
With per user-install, probably the same error?
Possible Solution
Apply the same change to chocolatey.ps1 that was done to installer.ps1
Steps to Reproduce (for bugs)
The same should be true if the installer task is called first with the ChocolateyInstall environment variable set to perform a per-user install. I expect the main ChocolateyCommand will throw the exception rather than finding the per-user install.
Context
This was while trying to use chocolatey to install a package for out build pipeline which runs on a self-hosted agent. It turns out that it's not a big problem for us because the package we were going to use Chocolatey to install has its own installer we can use anyway.
Your Environment
Azure Devops self-hosted build agent on a Windows 10 machine