0

I have build artifacts in a folder (e.g. FolderTest) that needs to be deployed to a specific folders locations on Windows such as:

C:
  FolderA
      FileA
      FileB
      FolderB
          FileC
          FolderC
             FilesD

Is it possible to use Chocolatey to deploy, copy files to different locations and maintain a software in that similar structure so that I can do upgrades, installs, rollbacks? Or should I even not use a package manager or use a different tool.

Squirrel
  • 1,283
  • 1
  • 13
  • 22

1 Answers1

1

The main installation script that is part of a Chocolatey Package, i.e. the chocolateyInstall.ps1 file, is a PowerShell Script. i.e. you can do anything that you want within that script, and that script will be executed when the package is installed. There is also the chocolateyUninstall.ps1 file, that can be used for removing the files that have been installed.

One other script that you can make use of is the chocolateyBeforeModify.ps1 file, which is used before uninstallation/upgrade. This would allow you to take any actions, for example stopping services before the uninstallation or the upgrade of the package.

So, bottom line, there is nothing to stop you putting the hierarchy that you mention in place, it would just mean that you would need to do the work in the installation scripts, to place the files into the correct locations on disk.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • Thanks. I am still trying to figure out how to package a simple folder with artifacts generated from Jenkins and copy it to somewhere in C:\. I am having a hard time finding any info like that. First time trying to package anything on Windows. – Squirrel Apr 17 '18 at 18:31
  • Are you able to share what you have? I would suggest first getting the nuspec defined, and getting the required files into the Chocolatey Package, and from there, worry about getting them elsewhere on the filesystem. Chocolatey, by default, will extract those files into it's lib folder. Once you have that working, you can work on moving the files elsewhere using the chocolateyInstall.ps1 file. – Gary Ewan Park Apr 17 '18 at 18:34
  • I have a folder on my Windows desktop with artifacts in a folder tree specified above I opened cmd and typed `choco new test-build` Opened the nuspec created, changed version and added `FolderA` folder to `tools` Added the line `` to `files` section in nuspec. Back to the cmd, executed `choco pack`. Now I have a nupkg file. If I execute `choco install test-build` the output says "The package was not found with the source(s) listed. Source(s): https://chocolatey.org/api/v2/" – Squirrel Apr 17 '18 at 19:30
  • Gotcha. So, assuming you haven't changed the default sources within Chocolatey, running `choco install test-build` will mean that chocolatey is looking for a package to exist on chocolatey.org. Since you haven't run `choco push` that package doesn't exist there, it only exists locally. Have a look at the documentation here: https://chocolatey.org/docs/create-packages#testing-your-package on how to test your locally created packages. – Gary Ewan Park Apr 17 '18 at 19:33
  • Thanks. I get tons of errors. I wish I had a working example just to move a file from location A to location B, etc. – Squirrel Apr 18 '18 at 15:16
  • Can you share, perhaps in a GitHub repo, the Chocolatey files for the package that you are trying to use? In terms of an example, you might want to have a look here: https://github.com/chocolatey/simple-server/tree/master/nuget This Chocolatey Package copies the contents of the package to another location on disk. – Gary Ewan Park Apr 18 '18 at 19:17
  • I don't have a public repo to show you but my needs are simply to copy files from a zip into specific folders in C:\. For example, test.zip if you unzip will explode into test1/test.txt then I would like to move test1/* into C:/example/test1 – Squirrel Apr 25 '18 at 13:14
  • That is definitely possible. Have you looked at the Unzip Helper function: https://chocolatey.org/docs/helpers-install-chocolatey-zip-package Here you can specify the folder that you want the zip file extracted to. – Gary Ewan Park Apr 25 '18 at 13:23