A script task allows you to configure input variables for a script as a simple key-value pair. The variable name should match the variable being used in the script when you configure a general input variable to customize the script.

About this task

Pipeline variables are runtime variables that are output from a previous task and are available for consumption by other tasks. The jayway/JsonPath property format is supported.

You can use the ${VAR} notation to have a task consume parameters that are available as pipeline runtime variables or the output produced from other tasks. You can select task output variables when you configure the release pipeline. The status variable is set by default to be shared by all of the tasks in the release pipeline. When these variables need to be consumed as a direct input for a field in the user interface, you can set them as BUILD_ID = 123, where 123 is the value of ${BUILD_ID}. The variable must be consumed as ${BUILD_ID}.

When this variable is consumed as vcac-123.war, where 123 is pulled from ${BUILD_ID}, it must be consumed as vcac-${BUILD_ID}.war.

Prerequisites

  • Verify that a script task is available in a release pipeline.

  • Verify that your script exists on a remote host that is configured in the script task. The script must have executable permission for a remote user to run it.

  • Verify that the folder where the remote script exists has permission to allow a file to be created.

  • Familiarize yourself with using task output variables. See Create a Release Pipeline.

Procedure

  1. Open a release pipeline.
  2. Select the new task in the stage.
  3. Confirm to save the pipeline.
  4. Select an Execute on Host type and add the applicable details.

    Option

    Description

    User defined hosts

    Enter one or more IP Addresses, DNS hostname, or release pipeline input variables as one of the valid hosts.

    For example, the input variable machine_ip can be 198.51.100.13. The user defined host can also have $machine_ip with static hostname and IP Address.

    Read From Pipeline or Task Property

    Provide a task output variable shared by another task or pipeline variable and apply filter criteria to restrict the script to run only on selected hosts.

    The pipeline variables are specified on the page before the modeling page. The run time values are applied when the release pipeline runs.

    For example, the task output variable ${StageName.TaskName.status.outputConfig.host} is bound and shared by all of the hosts. The status variable is set by default to be shared by all of the tasks in the release pipeline.

    To differentiate between a pipeline variable and a task output variable, the pipeline variable is always preceded by the constant variable. For example, ${pipeline.PipelineVariable}.

    Filter Criteria

    Set one of the following criteria from the drop-down menu.

    • ALL HOSTS. Run the script on all of the hosts that the host group variable gives.

    • STARTS WITH. From the host group, filter machines whose names start with the prefix as given by the user. The filter search criteria is case sensitive.

    • ENDS WITH. Filter machines whose names end with the suffix as given by the user.

    • EXACT MATCH. Run the script only on the machine whose name exactly matches the DNS hostname or IP Address.

  5. Type the host user name and password for a remote connection to the host.
  6. Select a Bash or PowerShell script from the drop-down menu.
  7. Select the script type.

    Option

    Description

    Remote Script File

    Specify the script file name and the path that already resides on the remote host.

    An example file path for a Bash script is /home/test/template/test.sh.

    User Defined Script

    Specify the inline Bash or PowerShell script to be executed on the remote host..

    Inline scripts enable dynamic creation and execution of a user-defined script on the remote host at the time of pipeline execution.

    An example of Bash inline script:

    message="Hello World"
    echo $message
    
  8. Enter the working directory path from where the script has to be executed.
  9. Configure the command-line arguments.

    The command-line arguments can be variables or binding variables. If the argument value has a space, enclose the value in double quotation marks.

    ${pipeline.buildNo} 10 2000 300 "test application"

    You can view the resolved values of the command-line arguments in the task results after the custom script task runs in the release pipeline.

  10. (Optional) : Select the script task output to share the output with other tasks in the release pipeline.

    The output contains the runtime data that is written to the $SCRIPT_RESPONSE_FILE file.

  11. Click Save.

Task Output Format for a Custom Script Task

The following task output format is an example for a custom script task.

[
  {
    "description": "Host Response",
    "name": "198.51.100.13",
    "value": "Sample Response of Linux Host 01. Sample Response of Linux Host 01.",
    "type": "STRING"
  },
  {
    "description": "Host Response",
    "name": "198.51.100.13",
    "value": "Sample Response of Linux Host 02. Sample Response of Linux Host 02.",
    "type": "STRING"
  }
]