Dowlnload packages from buildt in repository using powershell

Hi,

I have made an installer package as a zip package that I uploaded to the buildt in repository.
I want to create a powershell script template that can download a specified zip package, extract it, and the run a powershell script that is included in the zip package.
So my question is: How can I download a zip package from the build in repository, to a specified location, using powershell?

Hi Eirik,

Thanks for reaching out!

Instead of creating a step template based on the “Run a Script” template, why dont you base it on the “Deploy a Package” step instead? It basically solves the package download and extraction for you and you can enable the “Custom Deployment Scripts” feature for your custom script part.

Hope that helps,
Dalmiro

Hi,

Thank you. But the script that must be executed is a “Setup.ps1” file that is inside the package.
Is there any easy way to get the path to this script in the extracted package, so that in the deployment script could be just >.$PathToExtractedPackage\Setup.ps1, or something like that ? Without doing a lot of operations to calculate the path to the script in the exstracted package.

I was thinking it would just be easier if it was possible to handle the package download and extraction manually using powershell. That would allways give me control on the path to the Setup.ps1 script

Vennlig hilsen
Eirik

Hi Eirik,

Actually, there’s even an easier approach that I’m embarassed I didn’t propose earlier: Use the “Run a Script” step as base for your template, and choose the option Script Source -> Script inside of a package. Then on the “Script File Name” field, you can put the pat of the script based on the root of the package.

I’ve created this example step template for you to see what I’m talking about. Import it into your Octopus and check the values I entered in all the fields.

{
  "Id": "ActionTemplates-181",
  "Name": "Your amazing step template",
  "Description": null,
  "ActionType": "Octopus.Script",
  "Version": 1,
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Package",
    "Octopus.Action.Package.NuGetFeedId": "feeds-builtin",
    "Octopus.Action.Package.NuGetPackageId": "ID of the package that contains setup.ps1",
    "Octopus.Action.Script.ScriptFileName": "Setup.ps1 (or you could put #ScriptPath to use the example parameter)"
  },
  "Parameters": [
    {
      "Name": "ScriptPath",
      "Label": "Script Path",
      "HelpText": "Path of the script inside of the package. No need for double quotes.\n\n- If the script is in the root of the package, just put the name of the script here.\n\n- If the script is in a folder inside of the package, put it like Folder\\Script.ps1",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "$Meta": {
    "ExportedAt": "2016-04-05T16:46:50.796Z",
    "OctopusVersion": "3.3.6",
    "Type": "ActionTemplate"
  }
}

Keep in mind that the feature to “run scripts inside of packages” was introduced in Octopus 3.3

Hi,

Great, that works perfectly :slight_smile: thanks.

I will also need to manipulate values in an xml file in the package prior to running Setup.ps1.
We have an xml file in each zip package which is basicly various setup and config parameters. So we will need to be able to set these in the Octopus Deployment process prior to running “Setup.ps1”.
Any suggestions?
I havent’d had time to dive into this today, but maybe you know of an easy way of doing this.

Vennlig hilsen/Best regards
Eirik Rasmussen
System Developer
DIPS ASA
Telefon +47 75 59 22 44
Mobil +47 90 03 78 57

Fra: Dalmiro Grañas [mailto:tender2+d8f475b5e0@tenderapp.com]
Sendt: 5. april 2016 18:49
Til: Eirik Rasmussen eir@dips.no
Emne: Re: Dowlnload packages from buildt in repository using powershell [Questions #7675]

Hi again,

I was trying to find a template code for the step «Run a script», that I could use to create my own custom step template to first manipulate an xml file inside a package and then run a script inside the package, but could not find it.
Is it available?

Vennlig hilsen
Eirik Rasmussen
Systemutvikler
DIPS ASA
Telefon +47 75 59 22 44
Mobil +47 90 03 78 57

Fra: Dalmiro Grañas [mailto:tender2+d8f475b5e0@tenderapp.com]
Sendt: 5. april 2016 18:49
Til: Eirik Rasmussen eir@dips.no
Emne: Re: Dowlnload packages from buildt in repository using powershell [Questions #7675]

Hi Eirik,

From the script step, its not possible to execute custom code + code inside of your script. Its one or the other.

One of the goals of adding this “Script from package” feature is for users to be able to have their scripts versioned in a repository. The best practice would be for you to add the “ReadXML” logic inside of that same “Setup.ps1” script, so you have everything in 1 place. The rest of the files of your package will also be available in the script context where you are running “Setup.ps1”.

Let me know if that makes sense to you
Dalmiro

Hi,

Maybe I was not explaining it correctly. But the “Setup.ps1” script is reading the xml during execution. It is using the values found in the xml for various things during installation of the application. The zip package is a complete collection of dll’s, and installation scripts. So that prior to running setup, the user will just fill in the desired values in the xml, and then execute Setup.ps1.
And I want to achieve the same thing using Octopus, when deploying the package to different servers. So that in the “step” we can use variables as input to a script that sets these xml values.

So it is a pity that it will not be possible to first execute any custom code, and then execute the script inside the package.

I was searching for a variable that would give me the path to the installed package on the tentacle. Then I could install the package in the first step. Then in subsequent steps I could manipulate the xml and then execute Setup.ps1. But I did not find any such variable. It would maybe be possible to calculate the path, but it seemed a bit cumbersome.
Do you know of variable or method that gives me the path to the installed package? Or can I set an installation path for the package that will be the same across different servers?

Vennlig hilsen
Eirik Rasmussen
Systemutvikler
DIPS ASA
Telefon +47 75 59 22 44
Mobil +47 90 03 78 57

Fra: Dalmiro Grañas [mailto:tender2+d8f475b5e0@tenderapp.com]
Sendt: 6. april 2016 16:30
Til: Eirik Rasmussen eir@dips.no
Emne: Re: Dowlnload packages from buildt in repository using powershell [Questions #7675]

Hi Eirik,

I’m pretty sure this can be done, I just need a moment to build a test project to get my head around it. I’ll get back to you tomorrow with an approach, ok?

Cheers

Hi,

Sure. Awesome. Thank you very much for your support

Vennlig hilsen
Eirik Rasmussen
Systemutvikler
DIPS ASA
Telefon +47 75 59 22 44
Mobil +47 90 03 78 57

Fra: Dalmiro Grañas [mailto:tender2+d8f475b5e0@tenderapp.com]
Sendt: 6. april 2016 19:33
Til: Eirik Rasmussen eir@dips.no
Emne: Re: Dowlnload packages from buildt in repository using powershell [Questions #7675]

Hi again,

Thinking about it I found another approach. I do not really need to manipulate the xml file inside the package.
An alternative approach would be to have a separate step that I run to collect input values and write them to an xml file which can be stored in any folder on the tentacle.
Then I can send the path to this file as an input parameter to the Setup.ps1 in the next step.

So the Setup.ps1 will default read the xml file which is in the package, unless a path to an xml file is provided via a parameter. Just there is so many parameters in the xml file that they needs to be store in a file instead of sendt in via parameters to Setup.ps1 directly.

Vennlig hilsen
Eirik Rasmussen
Systemutvikler
DIPS ASA
Telefon +47 75 59 22 44
Mobil +47 90 03 78 57

Fra: Dalmiro Grañas [mailto:tender2+d8f475b5e0@tenderapp.com]
Sendt: 6. april 2016 19:33
Til: Eirik Rasmussen eir@dips.no
Emne: Re: Dowlnload packages from buildt in repository using powershell [Questions #7675]

Building the XML during the deployment is definitely a valid approach. Let me know how it goes.

Hi,

Building xml during deployment was easy. However, now I found out it is not possible to execute a script inside a package and to provide an input parameter to it. Getting a little bit frustrated about such limitation.
Do you have any suggetions how I can do this?

Vennlig hilsen
Eirik Rasmussen
Systemutvikler
DIPS ASA
Telefon +47 75 59 22 44
Mobil +47 90 03 78 57

Fra: Dalmiro Grañas [mailto:tender2+d8f475b5e0@tenderapp.com]
Sendt: 6. april 2016 21:26
Til: Eirik Rasmussen eir@dips.no
Emne: Re: Dowlnload packages from buildt in repository using powershell [Questions #7675]

I think the best would be for me to build a test project with this and then give you access to it so you can see my approach. I’ll need a few things from you:

  • Are you building the XML and doing whatever you need with it all in “Setup.ps1”, if not, is there a reason why you are not doing it?

  • What info are you putting into the XML? That should give me some context on how to approach this.

Regards,
Dalmi

I am also trying to find a way to get access to a variable that points to the path of the default repository in Octopus Deploy where packages, such as a NuGet package, gets stored. I came across this forum post but it does not seem like there currently is a feature such as this.

We are using TeamCity to create a NuGet package which contains a DACPAC and a Publish Profile. We need to extract the contents of this NuGet package on the Deployment Target, not a Tentacle. We have custom PowerShell code that we need to run that looks for the DACPAC and Publish Profile to be on the Deployment Target.

Hi Jason,

Thanks for reaching out! I’m not quite getting what you are trying to do.

You say on the Deployment Target, not a Tentacle., but Tentacles are Deployment Targets. Do you mean you need to extract the package on the Octopus Server instead of on another machine running the Tentacle?

If you can explain this a bit further, I’m sure we’ll be able to give you a hand.

Cheers,
Dalmiro

Hi Dalmiro,

I confused myself, my apologies. Our deployment targets are our tentacles. So essentially what we want to do is get the NuGet package in Octopus Deploy onto the tentacle and unpack it in a step. After that, we have custom PowerShell code in the next step to interact with the contents of the extracted NuGet package.

Thanks.

@Jason - Thanks for the extra info!

So essentially what we want to do is get the NuGet package in Octopus Deploy onto the tentacle and unpack it in a step.

That’s exactly what our “Deploy a Package” step does(see screenshot). It pushes a package from the feed of your choice (in the case the built-in one), then extracts it contents and if you want it can also run a script after the extraction.

Would that work for you?

Dalmiro

Yeah, after looking into it more, that is what we can do. I have the Nuget Package deployed and extracted to a custom location and then run my next step. Thanks.