Clubhouse.io - Harness

Hey All!

I’ve had a few conversations around integrations with Harness and other tools, what is and is not supported, and even when certain integrations will be coming. One of the great things about a Software-as-a-Service like Harness is that you get rapid integration support with use-case-directed development.

Obviously, we will need to supplement a stop-gap for some of these integrations in the meantime. The technology integration that this post covers will be Clubhouse.io!

Clubhouse Webhook

The first step is to add an API Webhook to Clubhouse:

  1. User Icon in the top right corner
    a. Settings
    1. API Tokens
      a. Token Name: harness
      b. Generate Token
      c. Add token as “clubhouse-token” in Harness Secrets Manager
      image

Delegate

Once you have the API Key for the integration, we need to set up the Harness Delegate for this process. The first thing will be to create a Delegate Profile with a simple apt-get -y install jq command.

image

After you apply that Delegate Profile to the Delegate, make sure to add a tag to the delegate named clubhouse

Required Clubhouse Information

There are some pieces of information that we need to get from Clubhouse to add to the Templates.

  1. Project ID
    a. If you don’t already have a desired project for these Stories to go into, you’ll need to make one.
    b. In Clubhouse, go to Projects on the left side of the screen, click into the project, and the Project ID will be in the top right

  2. Workflow States
    a. Click the Stories section in the left navigation bar and you’ll see a set of potential Workflow States. In the Templates, we will be using 3 states:

    1. Closed State (Example shows Completed)
    2. Approval State (Example shows Ready for Deploy)
    3. Update Story State (Example shows In Development)
      image
  3. Story Types
    a. From what I can see, there are only three story types:

    1. Chore
    2. Feature
    3. Bug
      b. The templates I have built out use the “chore” story type, but feel free to update that as needed.

Templates

This is where the majority of the engineering side of things comes into play. We’ll be creating three templates in the Template Library and using a fourth script in the Approval step.

  1. The first Template will be the Create Story template. I put the template in this location for you to use.
    a. The first thing to notice is that there are some variables being added in the comments section. These are Harness variables that will fill in different values for the Story comment. Feel free to change these as needed, but make sure you escape the quotes correctly.
    b. The next piece to notice is the “project_id” section. Currently, it is set to 2, but you will want to update that with your desired Project ID.
    c. The last piece to notice is “story_type”. As mentioned before, this is currently set to “chore”, but you can put this as whatever you want (it needs to be all lowercase)

  2. The second Template will be the Update Story template. I put the template in this location for you to use.
    a. The first thing to notice is that the first variable “IN_DEV_ID” is used to get the Workflow State ID number. If you do not want to use the “In Development” state, just change the section “select(.name==”In Development”)” to the desired name (case-sensitive to what is in Clubhouse).
    b. The next thing to notice is a comment adding section. Although you are not required to add a comment here, depending on the integration use case, you may want to add it in. If you do, just change the comment in the text section to match what you would like the comment to say. NOTE: The current Clubhouse API does not let you add a comment by updating the Story, but specifically calling a comment add API.
    c. The last thing is updating the state to whatever the declared state is in the IN_DEV_ID command.

  3. The third Template will be the Close Story template. I put the template in this location for you to use.
    a. The first thing to notice is the COMPLETED line, which gets the Workflow State ID for Completed and allows the Story to be updated to Completed for you. If you want a different Workflow State then Completed for the final part of the Story lifecycle, make sure to change the “Completed” part of “select(.name==“Completed”)” to match what you would like the Workflow State to be (case-sensitive to what is in Clubhouse).
    b. The second thing to notice, similar to the Update State command, is adding a comment in the Story.
    c. The last thing to notice is the moving of the Story into the Completed state.

  4. The last Script to use is not able to be put in the Template Library, so you will need to copy it directly into the Approval Step with a Custom Shell Script. I put the script in this location for you to use.
    a. The first thing to notice is the installation of the “jq” library with the auto-approve.
    b. The next thing to notice is the fetch of the Current Story’s Workflow State.
    c. The next thing to notice is the fetch of the desired Approval Workflow State. This one is where you will need to update the “select(.name==“Ready for Deploy”)” section to what you would like the Approval State to be.
    d. The last thing to notice is the 15 second loop that will check for Current Story Workflow State and see if it matches the Approval State. If it does not, it will try again in 15 seconds. You can have this run for the desired timeout of the Approval step. After the loop is finished, it will indicate an Approved state for you.

Template Library

When we add in the different Templates into the Template Library, we need to add some configurations to each Template.

  1. For the Create Story Template, you will need to do the following things:
    a. Add “STORY_ID” to the Script Output
    b. Add the following Variables:

    1. Name: API_URL
      a. Value: https://api.clubhouse.io/api/v3
    2. Name: SECRET
      a. Value: ${secrets.getValue(“clubhouse-token”)}
  2. For the Update Story Template, you will need to do the following things:
    a. Add the following Variables

    1. Name: API_URL
      a. Value: https://api.clubhouse.io/api/v3
    2. Name: SECRET
      a. Value: ${secrets.getValue(“clubhouse-token”)}
    3. Name: STORY_ID
      a. Value: ${STORY.STORY_ID}
  3. For the Close Story Template, you will need to do the following things:
    a. Add the following Variables

    1. Name: API_URL
      a. Value: https://api.clubhouse.io/api/v3
    2. Name: SECRET
      a. Value: ${secrets.getValue(“clubhouse-token”)}
    3. Name: STORY_ID
      a. Value: ${STORY.STORY_ID}

Workflow Integration

We will start by creating a Rolling Workflow to test these pieces out.

The first thing we will add is the Create Story Template:

  1. Add a step in the first Phase
    a. Click the Template radio button option at the top

    1. Click the “Link” button to the right of the “Create Story”
    2. Add “clubhouse” to the “Delegate Selector” option
    3. Check the “Publish Output in the Context”
    4. Add “STORY” to the “Publish Variable Name”
    5. Set “Scope” to Pipeline
      b. Move the Create Story step to the top of the Phase

  2. Add another step in the first Phase
    a. Click the Template radio button option at the top

    1. Click the “Link” button to the right of the “Update Story”
    2. Add “clubhouse” to the “Delegate Selector” option

  3. Add an Approval step in the second Phase
    a. Change “Ticketing System” to “Custom Shell Script”

    1. Add the Approval Script from the git repo into the script box


  4. Add a step in the last Phase
    a. Click the Template radio button option at the top

    1. Click the “Link” button to the right of the “Delete Story”
    2. Add “clubhouse” to the “Delegate Selector” option

Workflow Execution

Now, you will want to run the workflow to make sure that the different Templates are hitting the right spot and that the approval step works correctly for you. But, other than that, now you have a Clubhouse integration for your ticketing and approval processes!

Start of Deployment: New Story in Clubhouse


Story Update in Harness: Story moves in Clubhouse


Approval Step in Harness: Story is manually moved to desired state and Harness allows deployment to move on


Story is updated in Harness: Story moves to Completed in Clubhouse


Deployment Success

I will update this post as some functionality is improved or if new issues arise.

Don’t forget to Comment/Like/Share!

2 Likes