Choose your operating system:
Windows
macOS
Linux
In order to understand and use the content on this page, make sure you are familiar with the following topics:
In the following example, we have a sample command that prints out a Fibonacci sequence of numbers before exiting successfully. Follow this example to add a new command (or script) to your automation project:
Steps
Required Step
: Before continuing, make sure that there is an empty
*.cs
source file in the scope of your automation project.
-
First, make sure to name your source file, and in our example, we named our file
SimpleScript.cs
. -
Now, copy the following sample code into your script:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using AutomationTool; namespace SampleScript.Automation { // Use [Help()] attributes to document your command and its arguments. [Help("Sample script printing a Fibonacci sequence of values.")] [Help("Usage: SampleScript -Terms=<N>")] [Help("Terms=<N>", "N (int) represents how many terms to compute, and it must be greater than or equal to 1.")] // BuildCommand is the base class for all commands. public class SampleCommand : BuildCommand { public override void ExecuteBuild() { // The ParseParamInt() method retrieves a command line argument for this example. ParseParam() retrieves a bool, and ParseParamValue retrieves a string. int NumTerms = ParseParamInt("Terms"); if (NumTerms < 1) { throw new AutomationException("Invalid number of terms specified. Enter -help for syntax."); } else { LogInformation("Fibonnacci sequence:"); int TermA = 1; int TermB = 1; for (int TermIdx = 0; TermIdx < NumTerms; TermIdx++) { LogInformation(" {0}", TermA); int NextTerm = TermA + TermB; TermA = TermB; TermB = NextTerm; } } } } }
-
Finally, open a Command Prompt, navigate to
Engine\Build\BatchFiles
, and enterRunUAT.bat SampleCommand -terms=4
.
End Result
You should see the following output: