Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espoelstra/e63e6ef9f4fc2c1a85ddb3066a4cd33e to your computer and use it in GitHub Desktop.
Save espoelstra/e63e6ef9f4fc2c1a85ddb3066a4cd33e 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