Add a new script

Overview

To use scripts with Smart Tools, you need to add your scripts to the library in your account. To do this, you can enter your script by hand, copy and paste script content, or drag and drop your script file into the code editor that Smart Tools provides. The code editor provides basic editing features such as syntax highlighting and check, key bindings, drag and drop, and cut, copy, and paste.

Default values for script parameters

You can specify default values for script parameters. Values defined for parameters are saved and passed to the script at runtime. For example, you can assign values to the parameters defined in a script as follows:

script-parameters.png

As another example, if you are adding an installer script, you might specify a parameter called "mode" with default value "install." When you run the script, the value "install" is passed to the script and the installation is performed. You might also define a parameter called "location" with a default value of "/opt/packages" or another destination. You can also specify parameter values for ports, passwords, usernames, and so on. In some cases, if you plan to share a script, you can leave parameter values unspecified and let the users specify values based the requirements. 

Error handling

Smart Tools does not validate the parameters you include in scripts. When executed as part of a blueprint, this can cause the blueprint step to appear to succeed when it has actually failed. To mitigate this issue, include appropriate error handlers in your script code for Smart Tools to interpret script failures. For example, you can program your script to exit with an error message in case of a script failure.

To add a new script

  1. From the home page, click Smart Build.
  2. On the Library page, click New Script.
  3. Enter a script name and file extension. For example: bash, sh, ps1, perl, py, and so on.
  4. (Optional) Enter tags and description. Tags enable you to quickly search and retrieve your scripts from the existing scripts. To insert a tag, enter the tag and press Enter. You can enter a description that best describes the purpose of your script. Click Next
  5. Enter your script in the code editor.
  6. Ensure that the Line Ending option is set to Auto. You can set this option to Windows or Unix depending on the operating system that will run your script. The default setting is Auto. Line Ending is a special character or a sequence of characters that signifies the end of a line in your script. Scripts or text files created in Windows have different line endings against the files created in Unix/Linux. If you transfer scripts between Windows and Unix machines, ensure that the line endings are translated properly. Click Next.
  7. (Optional) Specify script parameters and click Next
    Note: Use only positional parameters (Example: $0, $1, $2). Do not use obvious parameters (Example: $foo).
  8. (Optional) Click Upload file(s) to attach files that support your script. You can select a single file or multiples files to upload.
  9. Click Finish.

The newly added script appears in the list on the Library page.

0 Comments