Skip to content

Instantly share code, notes, and snippets.

@DamianMac
Created October 30, 2014 02:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DamianMac/a944c0fcab6db531e7a5 to your computer and use it in GitHub Desktop.
Save DamianMac/a944c0fcab6db531e7a5 to your computer and use it in GitHub Desktop.
Executing a Script Task via the Octopus API
var server = "http://yourserveraddress:8065/"; //Your server and IP address
var apiKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXX"; // Get this from your 'profile' page in the Octopus web portal
var endpoint = new OctopusServerEndpoint(server, apiKey);
var repository = new OctopusRepository(endpoint);
var task = new Octopus.Client.Model.TaskResource();
task.Name = "AdHocScript";
task.Description = "Script invoked via API";
task.Arguments.Add("MachineIds", new Object[]{"machines-129"}); //Your machine ID
task.Arguments.Add("ScriptBody", "Write-Host \"Hello World\""); //Or you'll probably want to read in a script body from disk
var result = repository.Tasks.Create(task);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment