> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-platform/3.0/harness-platform-resources/approvals/approvals-tutorial.md).

# Approvals tutorial

This tutorial demonstrates how to use approvals by using a Harness CD pipeline as an example.

To follow along with this tutorial, you need:

* A **Harness pipeline** with active delegates and connectors. Please follow this [tutorial to get started with Harness Continuous Delivery (CD)](/continuous-delivery/troubleshooting-and-resources/tutorials/kubernetes-container-deployments/manifest.md). The tutorial below uses the Harness resources created as part of that tutorial.
* A **Harness User Group**. This tutorial uses [Harness User Groups](/harness-platform/3.0/harness-platform-resources/platform-access-control/add-user-groups.md) to manage user access. Create a user group named `approval-demo` at the account level, and add yourself as a user.

{% tabs %}
{% tab title="Manual Approval" %}
You can specify Harness User Group(s) to approve or reject a Pipeline at any point in its execution. During deployment, the User Group members use Harness Manager to approve or reject the Pipeline deployment manually.

{% tabs %}
{% tab title="Approval Stage" %}
Approvals can be added in between Stages to prevent the Pipeline execution from proceeding without an approval.

### Add an Approval stage <a href="#add-an-approval-stage" id="add-an-approval-stage"></a>

1. In the visual view of the pipeline, select **Add Stage**, and then select **Approval** as the stage type.
2. Name the stage `manual-approval-stage`, and select **Harness Approval** as the approval type.
3. Select the **Approval** step to open the **Manual Approval** pane. The **Manual Approval** pane includes predefined values for **Name**, **Timeout**, and **Approval Message**. You need to add the User Group you created under **Approvers**. You can also add **Approver Inputs** under this step.
4. Select **Apply Changes**. Your approval step is created.
5. **Save** the changes to the pipeline.
6. Since you already have a deploy stage present before the approval stage, drag the deploy stage to the right of the approval stage.
7. Verify and confirm the approval stage and deploy stage as shown below.
8. Select **Save**, and then select **Run** to run the pipeline.
9. As an approver, you'll receive notification on the **Console Log** pane under the **Logs** once the pipeline is running to approve or reject the pipeline. Click on **Approve** to run the pipeline.
   {% endtab %}

{% tab title="Approval Steps" %}
An Approval stage enables an approver to approve or reject the step, stopping the pipeline. The approver can also add comments and define variables for use by subsequent approvers and steps.

For this tutorial, we will use the visual view of the pipeline.

### Add an Approval step <a href="#add-an-approval-step" id="add-an-approval-step"></a>

1. In the CD stage **(deploy-guestbook)**, go to the **Execution** tab, and then select **Add Step**.
2. In the **Step Library**, under **Approval**, select **Harness Approval**. The **Manual Approval** pane includes predefined values for **Name**, **Timeout**, and **Approval Message**.
3. Add the User Group you created under **Approvers**. (Optional) You can also add **Approver Inputs** under this step.
4. Select **Apply Changes**. Your approval step is created.
5. Since you already have a deploy step present before the approval step, drag the deploy step to the right of Harness approval step.
6. Verify and confirm the pipeline stage and execution steps as shown below.
7. Select **Save**, and then select **Run** to run the pipeline.

{% hint style="warning" %}
Approval steps should not be added to run in parallel with other steps, including other Approval steps. The Harness Pipeline Studio will not allow you to add Approval steps in parallel with other steps, but the pipeline YAML editor does not prevent this setup. During execution, a successful parallel Approval step will not fail the deployment, but it is not a valid configuration because Approvals are checks on the release process and should always be used between steps.
{% endhint %}
{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="JIRA Approval" %}
{% hint style="info" %}
This feature is behind a Feature Flag and is available only to paid customers. Contact [Harness Support](mailto:support@harness.io) to enable the feature.
{% endhint %}

Jira issues can be used to approve or reject a pipeline or stage at any point in its execution. During deployment, the pipeline evaluates the fields in the Jira ticket based on criteria you define. Its approval or rejection determines if the Pipeline or stage may proceed.

You can add the Jira Approval step in Approval stages or in CD stages. The Jira Approval step prevents the stage execution from proceeding without an approval.

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Verify that you have the following:

1. **Personal Access Token:** Add the [JIRA API token](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/) as a Harness [Text Secret](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md#add-a-text-secret), with the name `jirapat`
2. **JIRA Connector:** For this tutorial you need to create a [JIRA Connector](/harness-ai/use-harness-platform/connectors/ticketing-systems/connect-to-jira.md#add-a-jira-connector) of the name `jira-approval`. If you've done the [Deploy using Kubernetes Manifest](/continuous-delivery/troubleshooting-and-resources/tutorials/kubernetes-container-deployments/manifest.md) tutorial, use this [jira-connector.yml](https://github.com/harness-community/harnesscd-example-apps/blob/master/harness-platform/approval/jira-connector.yml) to create connector under the project setup.
   * In the YAML, replace the `JIRA_URL` with your company base URL for Jira applications, for example: `https://mycompany.atlassian.net`.
   * Replace the `Username` with the email ID you use to log in to Jira.
3. **Jira Task:** Create a dummy [Jira issue](https://support.atlassian.com/jira-software-cloud/docs/create-an-issue-and-a-sub-task/) with type Task on the project for which your API has read access. Then set the status to `Done`.

### Limitations <a href="#limitations" id="limitations"></a>

Harness supports only Jira fields of type `Option`, `Array`, `Any`, `Number`, `Date`, and `String`. Harness does not integrate with Jira fields that manage users, issue links, or attachments. This means that Jira fields like Assignee and Sprint are not accessible in Harness' Jira integration.

### Add the Jira Approval step <a href="#add-the-jira-approval-step" id="add-the-jira-approval-step"></a>

1. In the CD stage **(deploy-guestbook)**, go to the **Execution** tab, and then select **Add Step**.
2. In the **Step Library**, under **Approval**, select **Jira Approval**.
3. Add a **Name** to the step, and set the **Timeout** to **20s**.
4. Add the **Jira Connector**, and then add the **Issue Key** of the Jira issue you created above.
5. Now set the **Approval Criteria**. There are two ways to do this. You can also specify a combination of the two:
   * **Conditions:** Use the **Jira Field**, **Operator**, and **Value** to define approval criteria.
   * **JEXL Expression:** Use the [JEXL Expression](https://commons.apache.org/proper/commons-jexl/reference/syntax.html) to define the same values as under conditions, for example: `<+issue.Status> == "Done"`
6. For this tutorial, select **Conditions** and specify the condition **Status = Done**.
7. Select **Apply Changes**. Your Jira Approval step is created.
8. Since you already have a deploy step present before the approval step, drag the deploy step to the right of Jira approval step.
9. Verify and confirm the pipeline stage and execution steps.
10. Select **Save**, and then select **Run** to run the pipeline.

### Add the Jira Approval stage <a href="#add-the-jira-approval-stage" id="add-the-jira-approval-stage"></a>

1. In the visual view of the pipeline, click on **Add Stage** and select the **Stage Type** as **approval**.
2. Name the stage as `jira-approval-stage` and select the type as **Jira**.

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>You do not need to use the Jira Create and Jira Update steps with the Jira Approval step. They are included in the <code>Jira Approval stage</code> because many users want to create a Jira issue, approve/reject based on its settings, and then update the issue all in one stage.</p></div>
3. Follow the steps [here](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/create-jira-issues-in-cd-stages.md#add-a-jira-create-step) and update the **Jira Create** step.
4. Similarly, follow the steps [here](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/update-jira-issues-in-cd-stages.md#add-a-jira-update-step), and update the **Jira Update** step.
5. For the **Jira Approval** step, follow the instructions above in [Add the JIRA Approval step](#add-the-jira-approval-step).
6. Drag the deploy-guestbook demo stage to the right of the jira-approval stage.
7. **Save** and **Run** the pipeline.
   {% endtab %}

{% tab title="ServiceNow Approval" %}
{% hint style="info" %}
This feature is behind a Feature Flag and is available only to our paid customers.
{% endhint %}

ServiceNow tickets can be used to approve or reject a pipeline or stage at any point in its execution. During deployment, a ServiceNow ticket's fields are evaluated according to the criteria you define, and its approval or rejection determines if the pipeline or stage may proceed.

Approvals can be added as stages or in-between stage steps to prevent stage execution from proceeding without approval.

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Verify that you have the following:

1. **ServiceNow Connector**: You need to connect to ServiceNow using the [connector](/harness-ai/use-harness-platform/connectors/ticketing-systems/connect-to-service-now.md#add-a-servicenow-connector).
2. **ServiceNow Ticket**: Create a dummy ServiceNow ticket with the `state` of the ticket set to `new`.

### Limitations <a href="#limitations" id="limitations"></a>

The ServiceNOw API only allows datetime and time values in the **UTC timezone**. Hence, for any **datetime/time fields** in **Harness ServiceNow steps** must be provided in **UTC format**.

### Add ServiceNow Approval Step <a href="#add-servicenow-approval-step" id="add-servicenow-approval-step"></a>

1. In the CD stage **deploy-guestbook**, go to the **Execution** tab, and then select **Add Step**.
2. In the **Step Library**, under **Approval**, select **ServiceNow Approval**.
3. Add a **Name** to the step, and set the **Timeout** to **20s**.
4. Add the **ServiceNow Connector** and the **Ticket Number** of the issue you created above.
5. Now set the **Approval Criteria**. There are two ways to do this. You can also specify a combination of the two:

   * **Conditions:** Use the **Field**, **Operator**, and **Value** to define approval criteria.
   * **JEXL Expression:** Use the [JEXL Expression](https://commons.apache.org/proper/commons-jexl/reference/syntax.html) to define the same values as under conditions, for example `<+ticket.state.displayValue> == "New"`.

   For this tutorial, use the JEXL Expression `<+ticket.state.displayValue> == "New"`.
6. Select **Apply Changes**. Your ServiceNow approval step is created.
7. Since you already have a deploy step present before the approval step, drag the deploy step to the right of ServiceNow approval step.
8. Verify and confirm the pipeline stage and execution steps.
9. Select **Save**, and then select **Run** to run the pipeline.

### Add ServiceNow Approval Stage <a href="#add-servicenow-approval-stage" id="add-servicenow-approval-stage"></a>

1. In the visual view of the pipeline, select **Add Stage**, and select **Approval** for the **Stage Type**.
2. Name the stage `snow-approval-stage`, and then select **ServiceNow** for the approval type.
3. Select **Set Up Stage**.
4. Under **Execution**, select the **ServiceNow Approval** step, and follow the instructions in [Add ServiceNow Approval Step](#add-servicenow-approval-step).
5. Drag the **deploy-guestbook** stage to the right of the **jira-approval** stage.
6. Select **Save**, and then select **Run** to run the pipeline.
   {% endtab %}
   {% endtabs %}
