private static void CreateActionTemplate(IOctopusRepository repository) { string name; string scriptBody; using (var webClient = new WebClient()) { var json = webClient.DownloadString( "https://raw.githubusercontent.com/OctopusDeploy/Library/master/step-templates/redgate-create-database-release.json"); var o = JObject.Parse(json); name = (string)o["Name"]; var properties = o["Properties"]; scriptBody = (string)properties["Octopus.Action.Script.ScriptBody"]; } var actionTemplateResource = new ActionTemplateResource { Name = name, ActionType = "Octopus.Script", Properties = { { SpecialVariables.Action.Script.ScriptBody, scriptBody } } }; repository.Client.Post(repository.Client.RootDocument.Links["ActionTemplates"], actionTemplateResource); }
public async Task <TaskResource> ExecuteActionTemplate( ActionTemplateResource template, Dictionary <string, PropertyValueResource> properties, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null, BuiltInTasks.AdHocScript.TargetType?targetType = null) { if (string.IsNullOrEmpty(template?.Id)) { throw new ArgumentException("The step template was either null, or has no ID"); } await EnsureValidTargetType(targetType); var resource = new TaskResource() { SpaceId = template.SpaceId }; resource.Name = BuiltInTasks.AdHocScript.Name; resource.Description = string.IsNullOrWhiteSpace(description) ? "Run step template: " + template.Name : description; resource.Arguments = new Dictionary <string, object> { { BuiltInTasks.AdHocScript.Arguments.EnvironmentIds, environmentIds }, { BuiltInTasks.AdHocScript.Arguments.TargetRoles, targetRoles }, { BuiltInTasks.AdHocScript.Arguments.MachineIds, machineIds }, { BuiltInTasks.AdHocScript.Arguments.ActionTemplateId, template.Id }, { BuiltInTasks.AdHocScript.Arguments.Properties, properties }, { BuiltInTasks.AdHocScript.Arguments.TargetType, targetType }, }; return(await Create(resource)); }
public ActionTemplateResource FindByName(string name) { ActionTemplateResource template = null; name = (name ?? string.Empty).Trim(); client.Paginate <ActionTemplateResource>(templatesPath, page => { template = page.Items.FirstOrDefault(t => string.Equals((t.Name ?? string.Empty), name, StringComparison.OrdinalIgnoreCase)); // If no matching template was found, then we need to try the next page. return(template == null); }); return(template); }
public async Task <ActionTemplateResource> FindByName(string name) { ActionTemplateResource template = null; name = (name ?? string.Empty).Trim(); var templatesPath = client.RootDocument.Link("ActionTemplates"); await client.Paginate <ActionTemplateResource>(templatesPath, page => { template = page.Items.FirstOrDefault(t => string.Equals((t.Name ?? string.Empty), name, StringComparison.OrdinalIgnoreCase)); // If no matching template was found, then we need to try the next page. return(template == null); }) .ConfigureAwait(false); return(template); }
public Task <ActionTemplateResource> Modify(ActionTemplateResource resource) { return(client.Update(resource.Links["Self"], resource)); }
public async Task <ActionTemplateResource> Create(ActionTemplateResource resource) { var templatesPath = await client.Repository.Link("ActionTemplates").ConfigureAwait(false); return(await client.Create(templatesPath, resource).ConfigureAwait(false)); }
/// <summary> /// Gets the Usage resource of the passed ActionTemplate. /// </summary> /// <param name="client">The Repository this is tacked on to.</param> /// <param name="actionTemplate">The action template to get more info about.</param> /// <returns>The List of action template usages.</returns> internal static IEnumerable <ActionTemplateUsageResource> GetActionTemplateUsage(this IOctopusClient client, ActionTemplateResource actionTemplate) { return(client.Get <IEnumerable <ActionTemplateUsageResource> >(actionTemplate.Link(ResourceStrings.UsageLink))); }
/// <summary> /// Gathers the Action Template Usage Info, Used for gathering what project a template may be tied to /// </summary> /// <param name="octRepository">The repository to call against.</param> /// <param name="actionTemplate"></param> /// <returns></returns> public IEnumerable <ActionTemplateUsageResource> GetActionTemplateUsage(OctopusRepository octRepository, ActionTemplateResource actionTemplate) { return(octRepository.Client.GetActionTemplateUsage(actionTemplate)); }
public ActionTemplateResource Create(ActionTemplateResource resource) { return(client.Create(templatesPath, resource)); }