// Copyright Epic Games, Inc. All Rights Reserved. using EpicGames.Core; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; using System.Xml; namespace AutomationTool.Tasks { /// /// Parameters for a Kubectl task /// public class KubectlTaskParameters { /// /// Command line arguments /// [TaskParameter] public string Arguments; /// /// Base directory for running the command /// [TaskParameter(Optional = true)] public string BaseDir; } /// /// Spawns Kubectl and waits for it to complete. /// [TaskElement("Kubectl", typeof(KubectlTaskParameters))] public class KubectlTask : BgTaskImpl { /// /// Parameters for this task /// KubectlTaskParameters Parameters; /// /// Construct a Kubectl task /// /// Parameters for the task public KubectlTask(KubectlTaskParameters InParameters) { Parameters = InParameters; } /// /// Execute the task. /// /// Information about the current job /// Set of build products produced by this node. /// Mapping from tag names to the set of files they include public override Task ExecuteAsync(JobContext Job, HashSet BuildProducts, Dictionary> TagNameToFileSet) { FileReference KubectlExe = CommandUtils.FindToolInPath("kubectl"); if (KubectlExe == null) { throw new AutomationException("Unable to find path to Kubectl. Check you have it installed, and it is on your PATH."); } IProcessResult Result = CommandUtils.Run(KubectlExe.FullName, Parameters.Arguments, null, WorkingDir: Parameters.BaseDir); if (Result.ExitCode != 0) { throw new AutomationException("Kubectl terminated with an exit code indicating an error ({0})", Result.ExitCode); } return Task.CompletedTask; } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter Writer) { Write(Writer, Parameters); } /// /// Find all the tags which are used as inputs to this task /// /// The tag names which are read by this task public override IEnumerable FindConsumedTagNames() { yield break; } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { yield break; } } }