Artifacts in Octopus provide a convenient way to collect files from remote machines, and copy them to the Octopus server, where they can then be viewed from the web interface. Examples of where artifacts may be useful are:
- Collecting log files from other programs
- Copying configuration files so you can inspect to see if the right values were replaced
Remember that whatever files you want to import into Octopus Deploy need to be accessible by the account performing the deployment. For example, the Tentacle process in Windows, or the SSH account in Linux.
After the script runs the files will be uploaded to Octopus Server and made available as deployment artifacts which are available for download from the task output, or via the Octopus API.
Collecting artifacts using scripts
You can collect artifacts using any of the scripting languages supported by Octopus. In each case we make special functions available to your scripts by bootstrapping them with a template defined in the open-source Calamari project.
From a PowerShell script, you can use the PowerShell CmdLet
New-OctopusArtifact to collect artifacts. The CmdLet takes two parameters:
[string]$path- the local path to the file that will be made an artifact
[string]$name- an optional friendly name to give the artifact, usually to distinguish it if collecting multiple artifacts with the same name from different machines. Defaults to the file name in
New-OctopusArtifact -Path "C:\Windows\System32\drivers\etc\hosts" -Name "$([System.Environment]::MachineName)-hosts.txt"
From a C# script, you can use the
public static void CreateArtifact(string path, string fileName = null) method to collect artifacts. The method takes two parameters with the same purpose as the PowerShell CmdLet.
Octopus.CreateArtifact(@"C:\Windows\System32\drivers\etc\hosts", System.Environment.MachineName + "-hosts.txt");
error CS1501: No overload for method 'CreateArtifact' takes 2 arguments.
fileName optional parameter was added in Calamari 3.1.24 which shipped as part of Octopus 3.2.12
In a Bash script you can use the
new_octopusartifactfunction to collect artifacts. This function takes two positional parameters with the same purpose as the PowerShell CmdLet.
new_octopusartifact /etc/hosts $(hostname)-hosts.txt
F# support is available in Octopus Deploy 3.4 (or newer).
From a F# script, you can use the
createArtifact : path:string -> fileName:string option -> unit function to collect artifacts. The function takes two parameters with the same purpose as the PowerShell CmdLet.
Octopus.createArtifact @"C:\Windows\System32\drivers\etc\hosts" (Some (System.Environment.MachineName + "-hosts.txt"))