Use Script Based Services

Updated 6 months ago by Chakravarthy Tenneti

You can create and add Bash and PowerShell scripts as Services. You can use the options and templates available in Harness to use these scripts in your deployment.

In this topic:

Before You Begin

  • Read the Create an Application topic to get an overview of how Harness organizes Services.
  • Read the Add a Service topic to understand the process to add a Service to an Application.
  • Read Configuration as Code to see how you can quickly configure your Harness Service using your existing YAML in Git.

Option 1: Edit Default Commands

When you create a script-based Service, Harness automatically generates the commands needed to install and run the application in the Artifact Source on the target host(s). You can edit these default commands.

You can also add templates from the template library or add commands as shown in the following options.

Moving Commands

As part of the Deployment Specification steps (Start, Install, or Stop), you can drag and move a command in the place of another command or before or after another command. All the other commands are moved accordingly and the script is updated automatically.

Option 2: Use Template Library

You can use the wealth of scripts available in the Template Library to rapidly develop your script. For more information, see Use Templates.

  1. In the Script section of Deployment Specification, click Add Command. The Add Command dialog appears.
  2. Click From Template Library. The Template Library is displayed. Find the template you need.
  3. Click Link or click the drop-down menu and choose Copy. You can link to a template or copy a template to your service. If you link to the template, when that version of the template is updated in the Template Library, your script is also updated. If you copy a template, there is no link to the Template Library. If you link to a template, you may only edit the template from the template dialog. You cannot edit the template in your service.
  4. Edit the script if needed and click SUBMIT. The script is added to your service.
    Every time you edit a template, you create a new version of it. To switch versions, click the three dots on the script title bar and choose Manage Versions.
  5. To edit the variables used in the script, click Variables. The Edit Command dialog opens. Edit the variables and click SUBMIT.

Option 3: Create a New Command

Harness provides multiple commands to manage the deployment of your application.

  1. In the Script section of Deployment Specification, click Add Command. The Add Command dialog appears.
  2. Click Create New.
  3. In Name, enter a name for the new command that describes its function.
  4. From Command Type, select the function of the command, such as Start, Install, Disable, etc.
  5. Click Submit. The new command is added under Script.
  6. Hover over the Add button to see the available commands.
  7. Click a command from the list. The dialog for the command appears. For example, here is the dialog for the Docker Start command.
    The dialog contains a default script relating to it type. The script is prefigured for variables for common application information.
  8. From Script Type, select BASH or POWERSHELL.
  9. Modify the script is needed and click SUBMIT. The command is added to the Script section:
  10. Repeat the above steps to add more commands to your script.


How did we do?