Example showing how publish artifacts from Powershell

Using Octopus Deploy
I am wondering if there is a gist or link with a reference to doing this from Powershell.
Sorry to ping the question forum on this, but I wasn’t having success find a simple example by my searching.


No worries! That’s what this forum is for :). This example will add MyFile.txt as an artifact for your deployment

New-OctopusArtifact C:\Test\MyFile.txt

Hope that helps


A couple of follow-up questions, if I might:

  1. is there a way to detect from my deploy.ps1 IF its executing via Octopus deploy?
    I need to be able to “unit-test” the deploy.ps1 outside of Octopus
    I would like to detect the condition, and “skip” the posting of artifacts to Octopus.
  2. Also, is there a set of Powershell modules for Octopus I should load?


  1. Hmm not exactly. You could check the value of $env:UserName during your script to see which user is running the Powershell process and take actions based on that. I’m asuming you want to take actions based on If the script is being executed during a “unit-test” or during an actual deployment. If that is the case, building conditions based on the user running the process (the “unit-test” user vs the account running the Tentacle service) might do.
  2. No, the New-OctopusArtiact cmdlet comes built in with Octopus, you dont need to load any module on your own.

Hope that helps,


Thanks Dalmiro,
Before unit-testing our framework “spoofs” some settings for Octopus using a map named as $OctopusParameters, namely:


after having extracted the nuget contents.

It then calls the deploy.ps1, which ultimately forwards the deployment request to a deployment handler based (again) on our internal framework.
That linkage is what I want to test outside of the “Octopus container.”

I have modified our deploy.ps1 to look for a NON-NULL value of the system variable Octopus.Deployment.Id (i.e., $OctopusParameters[‘Octopus.Deployment.Id’])

In our unit-test case, this is null, which causes the call to New-OctopusArtifact to be omitted in the case.

It looks like, in addition, I need to iterate objects, because it turns out we actually have an entire directory of artifacts we want to publish to Octopus and

New-OctopusArtifact -Path “$publish.Path***” appears to be illegal.