ServiceNow Integration

Updated 2 weeks ago by Michael Cretzman

Using ServiceNow (SNOW) tickets from one or more ServiceNow instances, you can track/audit the progress of Harness deployments (and Pipelines) and approve/reject Pipeline stages.

This topic covers:

ServiceNow Collaboration Provider

To use ServiceNow integration in your Workflow or Pipeline, you need to add a ServiceNow account as a Harness Collaboration Provider.

For steps on adding ServiceNow as a Collaboration Provider, see ServiceNow. Once you have added a ServiceNow account to Harness, you can integrate ServiceNow into your Workflows and Pipelines.

Create and Update Tickets in a Workflow

You can create and update ServiceNow tickets during the execution of a Harness Pipeline Stage or Workflow. This section will cover creating and updating tickets in a Workflow. We will create a ServiceNow ticket in an existing Workflow's Pre-deployment Steps, and then update the same ticket in the Post-deployment Steps as the Workflow completes.

To use a ServiceNow ticket as part of a Workflow, do the following:

  1. Ensure you have added a ServiceNow account as a Harness Collaboration Provider, as described in ServiceNow.
  2. Create a new or open an existing Harness Workflow. In this example, we are using a Canary Deployment Workflow.
  3. In Pre-deployment Steps, click Add Step.
  4. In the Add Command, click ServiceNow.

The ServiceNow dialog appears.

The ServiceNow dialog has the following fields:

  • Title - By default, the step is titled ServiceNow. If you are creating a ServiceNow ticket, you might want to rename the step ServiceNow Creation, for example.
  • Request Type - Select Create an Issue. Update an issue is discussed later.
  • Connector - Select the ServiceNow account to use by selecting the ServiceNow Collaboration Provider set up for that account. For more information, see ServiceNow.

    When you select the ServiceNow Collaboration Provider, any account-specific fields in that ServiceNow account are pulled into the dialog. For example, here the fields Impact and Urgency and their values are displayed:
  • Ticket Type - Select a ServiceNow ticket type from the list of types.
  • Short Description -Add a description for the ticket you are creating. This will be the ticket title. You can use Harness variables in the Short Description and Description fields. Simply enter $ and a list of possible variables appears.
  • Description - Add the ticket description.
  • Output in the Context - Select this option to create a variable for the ServiceNow issue that you can reference in another step in this Workflow or in a Pipeline.
  1. Select Output in the Context, and in Variable Name, enter a name, such as snow.
  2. In Scope, select PipelineWorkflow, or Phase. The Pipeline scope is the widest, and includes the Workflow and Phase scopes. Next widest is Workflow, and includes any phases within that Workflow. And finally, Phase scopes the variable to the Workflow phase in which it was created.

    For example, a variable with a Pipeline scope can be used by any step in the Pipeline which uses this Workflow, such as an Approval Step. For this example, we will use the Pipeline scope.

    Now that there is an output variable, you can add activity to the same ServiceNow ticket using the variable name. We will use this variable when we update this ticket, but for now note that the syntax to reference the variable is ${variable_name.issueId}. For example, ${snow.issueId}.
Presently, the only ServiceNow issue element you can reference is the issue ID using issueId. Harness will be adding more issue element variables in the near future.

When the ServiceNow dialog is complete, it will look something like this:

Note the use of Harness variables in the Description field:

Deploying Workflow: ${workflow.name}
Deployment URL: ${deploymentUrl}

The variables will be replaced at runtime with deployment information. For more information on Harness variables, see Variables and Expressions in Harness.

When the Workflow is deployed, in the Harness Manager Deployments page, you can see a link to the ServiceNow ticket created by the ServiceNow step:

Click on the link in Deployments to view the ticket in ServiceNow.

To see the variables you used in the Descriptions field, click the ellipsis in the Details section, and click View Execution Context.

The runtime output is displayed:

Next, we will update the ServiceNow ticket in the Post-deployment Steps in the Workflow.

  1. In Post-deployment Steps, click Add Step, and click ServiceNow. The ServiceNow dialog appears.
  2. In Request Type, click Update an Issue. The dialog changes to display the update settings.

  1. In Connector, select the same ServiceNow Collaboration Provider you used to create the ticket.
  2. In Ticket Type, select the same type.
  3. In Issue Number, use the output variable expression to identity the ticket you created in the ServiceNow step where you created the ticket. The output variable name was snow, so the variable is ${snow.issueId}.
  4. In Update State, update the ticket information.
  5. In Add work notes, add any notes. You can also use Harness variables, for example: Started progress on Workflow: ${deploymentUrl}.
  6. You can also output this issue number using Output in the Context and change the scope.

When you are done, the dialog will look something like this:

Click SUBMIT. Your Workflow now has a ServiceNow step in its Pre and Post-deployment Steps:

When Workflow is deployed, the ServiceNow steps are displayed.

Clicking on the link to the ServiceNow ticket takes you directly to the ticket in ServiceNow, and reveals all the activity logged during the Workflow steps:

snow_ticket

Now you know how to create and update ServiceNow tickets in your Workflows. Next, we'll look at using ServiceNow tickets for Pipeline Approval stages.

ServiceNow-based Approvals

You can use a ServiceNow ticket as an approval stage in a Harness Pipeline and, when the ticket is updated, the Pipeline stage can be approved or rejected. For example, changing the State attribute of a ServiceNow ticket from Resolved to Approved could automatically approve the execution of a Pipeline stage or Workflow deployment in Harness.

For more information, see ServiceNow-based Approvals.


How did we do?