Skip to content

Instantly share code, notes, and snippets.

@rpresser
Created December 18, 2019 19:48
Show Gist options
  • Save rpresser/eb63b732932a2e9bcbdd0d7c8c7f9eca to your computer and use it in GitHub Desktop.
Save rpresser/eb63b732932a2e9bcbdd0d7c8c7f9eca to your computer and use it in GitHub Desktop.
Download OctopusDeploy artifacts from a task (C#)
// This is C# code meant for use in LINQPad.
// Add nuget reference to Octopus.Client.
// Provide your OctopusDeploy server URL and APIKEY in environment variables (see the first line below),
// or hardcode them, or whatever you wish.
var endpoint = new OctopusServerEndpoint(Environment.GetEnvironmentVariable("OCTOPUS_SERVER"),Environment.GetEnvironmentVariable("OCTOPUS_CLI_API_KEY"));
var repository = new OctopusRepository(endpoint);
string taskID = "ServerTasks-104598";
var task = repository.Tasks.Get(taskID);
foreach (var art in repository.Artifacts.FindRegarding(task).Items)
{
string savePath = Path.Combine(@"C:\temp\savefolder",art.Filename);
var c = repository.Artifacts.GetContent(art);
var f = File.Create(savePath);
c.CopyTo(f);
f.Close();
c.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment