Skip to main content

Getting Started with Workflows

Goal

This will help you setup a Workflow in IDP which automates GitHub Repo Onboarding for users.

Pre-requisite

Add Connector

  1. Go to Admin -> Git Integrations.
  2. Add a New Git Integration with type as GitHub.
  3. Now Select the GitHub Connector and Save Changes, follow the steps to add a new connector
info

Make sure the Connector URL used here is pointed towards the org where you want to create the new repo and the token used have write permission for the repo also Enable the API while creating connector.

Create Harness Pipeline with IDP Stage

  1. Go to Admin -> Pipelines.
  2. Now start with Create a Pipeline.

  1. Add a Name, select the type as Inline and Continue.

  1. Add Stage and Select Stage Type as Developer Portal.

  1. Select the infrastructure as Harness Cloud.

  1. Now let's create some variables which we will be using in further steps, add the following Custom Variables (stick to the exact naming convention for variables as provided as these will be used as a reference to input values into the pipeline)
    • github_org
    • github_repo The variables are of Type String and the Values are set to Runtime Input. Apply the changes

  1. Now Continue to Execution and Add Step, under Git Repository Setup select Create Repo.

  1. Under Step Parameters, select the Repository Type and add the Connector you created under Select codebase repo connector.
  2. Now under Organization and Repository Name add the variables you created as Expressions (<+pipeline.variables.github_org> and <+pipeline.variables.github_repo> ).
  3. Add a Repository Description, Apply Changes and Save the pipeline.

Create Template

If you want to use our sample templates you can skip this step and go to register template step

The template is defined in a YAML file named template.yaml. The syntax of the template definition is owned by backstage.io while the workflow runs on a Harness pipeline of your choice.

The following is the example template with custom action to create a new repository.

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
# some metadata about the template itself
metadata:
name: Workflows-Quickstart
title: Create a New GitHub Repository
description: Creates a new GitHub Repository
spec:
owner: service.owner
type: service
# these are the steps which are rendered in the frontend with the form input
parameters:
- title: Fill in the repo details
required:
- github_org_name
- github_repo_name
properties:
github_org_name:
title: GitHub Organization
type: string
description: Name the org where you want to add the new repository
github_repo_name:
title: Repository Location
type: string
description: Name the new repository that you want to create
token:
title: Harness Token
type: string
ui:widget: password
ui:field: HarnessAuthToken
# here's the steps that are executed in series in the scaffolder backend
steps:
- id: trigger
name: Onboarding a New GitHub Repository
action: trigger:harness-custom-pipeline
input:
url: "URL_of_the_Harness_Pipeline_Created_Above"
inputset:
github_org: ${{ parameters.github_org_name }}
github_repo: ${{ parameters.github_repo_name }}
apikey: ${{ parameters.token }}
# The final step is to register our new component in the catalog.

output:
links:
- title: Pipeline Details
url: ${{ steps.trigger.output.PipelineUrl }}

In the above template we have used the Harness Trigger Custom Action, which takes the exact variable name github_org and github_repo you created for your pipeline as input and a token as apikey

  1. Copy the above template file in your git provider, and save it as workflow.yaml.

Register Template in IDP

  1. In the left navigation, select Create, and then select Register Software Component.

  1. Enter the URL to your new workflow.yaml.

  2. Select Import.

  1. Now click on the template name

Use Workflows to Create a Repo

  1. Once you're on the entity page for template, Launch the Template.

  1. Now fill the fields as:
    • Repository Location: Add a name for the repository you wanted to create.
    • GitHub Organization: Add the org where you want add your new repository, usually GitHub URL are of the format https://github.com/org_name/repo_name/

  1. Now Trigger the flow, it will create a new GitHub repo.

Delete the Template

If you want to unregister or delete the template follow the steps mentioned here.

Further Reading

Self Service Onboarding in IDP is powered by scaffolder templates and Harness Pipeline(IDP Stage) . Follow the tutorials to learn more about it.

  1. Create a service onboarding pipeline (using IDP Stage)

  2. Getting started with service onboarding pipeline (using Custom Stage)

  3. Use Harness IDP for self serviced Harness CI/CD onboarding