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
- Go to Admin -> Git Integrations.
- Add a New Git Integration with type as GitHub.
- Now Select the GitHub Connector and Save Changes, follow the steps to add a new connector
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
- Go to Admin -> Pipelines.
- Now start with Create a Pipeline.
- Add a Name, select the type as Inline and Continue.
- Add Stage and Select Stage Type as Developer Portal.
- Select the infrastructure as Harness Cloud.
- 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 TypeString
and the Values are set toRuntime Input
. Apply the changes
- Now Continue to Execution and Add Step, under Git Repository Setup select Create Repo.
- Under Step Parameters, select the Repository Type and add the Connector you created under Select codebase repo connector.
- Now under Organization and Repository Name add the variables you created as Expressions (
<+pipeline.variables.github_org>
and<+pipeline.variables.github_repo>
). - 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
- Copy the above template file in your git provider, and save it as
workflow.yaml
.
Register Template in IDP
- In the left navigation, select Create, and then select Register Software Component.
-
Enter the URL to your new
workflow.yaml
. -
Select Import.
- Now click on the template name
Use Workflows to Create a Repo
- Once you're on the entity page for template, Launch the Template.
- 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/
- 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.