This works fine and installs choclatey. however our next step then runs:
cinst mysql
This should install mysql, but instead we get an error:
cinst : The term ‘cinst’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Windows\system32\config\systemprofile\AppData\Local\Tentacle\Temp\8456dbdd-663a-4c0b-8e2a-1cafe1e138be.ps1:2 char:1 + cinst mysql
To diagnose further I echo’ed out the path variables prior to running cinst using: $env:Path.split(";")
This returned:
*C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0*
Note there are no Chocolatey paths here
If I then re-run the deployment running only the second step I still get the same error.
It is only when I restart the tentacle, and re-run the second step that I get the correct path variables and cinst starts working: C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Chocolatey\bin
Chocolatey (v0.9.8.23) is installing ‘mysql’ and dependencies…
Is there any way of making the Path update without restarting the tentacle, or is there some way of automatically restarting the tentacle within a step?
Thanks for getting back to me. We are currently using Octopus Deploy
2.3.3.1369.
I already have the install chocolatey nuget and install mysql as two
separate steps in the deployment process.
Using the full path to cinst in this case will not solve the issue, as
chocolatey all the chocolaty packages use the environment variables and it
is not just used to find the path of the cinst exe.
I think that the main issue here is that the Tentacle will only read the
environment variables once, at tentacle service startup. It seems that all
powershell scripts from deployments are run by a powershell host within the
tentacle, the problem is that the deployment scripts will share the same
session, and in doing so, the same environment variables which are cached
in the session.
To recreate this issue without chocolatey:
Start a tentacle on a server.
Add a new environment variable via the Windows UI (make sure you add
this for the user that runs the build e.g. "NT Authority\System"
3.Create a build in OD with a deployment step that runs a powershell script
3.1. The script contents should be Write-Host
$env:MyNewEnvironmentVariableName
Run the script and you should notice that your new environment variable
is not written out.
The current behaviour kind of makes Environment variables a no-go zone when
doing OD deployments
After doing some more thinking on this I have come up with one solution
which seems to work, which is to run something like the script defined here
at the top of all scripts, this gets the latest environment variables from
the system and updates the sessions cache of them. I think it would be
useful if OD ran something similar between each deploy process step
(perhaps it should be an option?)
I submitted a pull request to the Step template for chocolatey that should solve this problem of installing and then immediately using it.
If you call the method: [Environment]::GetEnvironmentVariable(“chocolateyInstall”, “Machine”) it will directly query the registry for the updated environment variable and not rely on the variables that were cached when the Tentacle was created.
I’m relying on the chocolateyInstall environment variable created by the latest version of chocolatey, but you could also get the path variable that same way if you need it.
Hi Joe, I have just tried your step templates, Chocolatey - Ensure Installed seems to work, but Chocolatey - Install Package complains about “Chocolatey was not found at \bin\cinst.exe.”
Make sure the ChocolateyInstall environment variable exists on the machine you’re using this on. I was installing chocolatey on machines that had never had chocolatey installed before, and the install was creating an environment variable called ChocolateyInstall which pointed to the location C:\ProgramData\chocolatey and in that directory there should be a \bin\cinst.exe.
The change I made to this step template was to call the .net function GetEnvironmentVariable to get the variable so I would not have to reboot the Octopus tentacle process in order to start using chocolatey. It seems to be working successfully for me on the win 2k8 machines I’ve been using it on.
It could be there are some limitations to this that I just haven’t run into.