Create a remote pipeline template
Harness enables you to add Templates to create re-usable logic and Harness entities (like Steps, Stages, and Pipelines) in your Pipelines. You can link these Templates in your Pipelines or share them with your teams for improved efficiency.
Templates enhance developer productivity, reduce onboarding time, and enforce standardization across the teams that use Harness.
A Pipeline Template lets you distribute reusable pipelines across your team or among multiple teams. Instead of building pipelines from scratch, Pipeline templates simplify the process by having parameters already built-in.
For example, you can automate your build and deploy services by adding a Pipeline Template. You can link the following Templates to your Pipeline Template:
- Build stage - To push the artifact to the registry, run tests, and security scans.
- Staging deploy stage - To deploy to Dev, QA.
- Approval stage - To add approval stages for PROD.
- Prod deploy stage - To deploy to Production.
You can create a Template and save it either in Harness or in a Git repository using the Inline or Remote option respectively.
This topic walks you through the steps to create a Remote Pipeline Template.
Permissions
To create a Remote Pipeline Template make sure you have Create/Edit and Access permissions for Templates.
Remote pipeline template overview
Harness Pipeline Templates give you the ability to enforce consistency. You can save your Pipeline Templates in different Git repositories. These are called Remote Pipeline Templates.
For example, if you have a core Pipeline that you want all of your teams to use, you can put the template in a core repo and then refer to it. Now you can reuse this Template.
For information on inline pipeline templates, see create a pipeline template.
Use a remote pipeline template
Harness Templates let you reuse a Pipeline Template to create a Pipeline, or share it with your teams for enhanced efficiency.
Whenever you use a Remote Pipeline, Harness resolves the repositories when your Pipeline starts up.
You can have one of the following scenarios when using a Template in your Pipeline:
- Remote Pipeline Template and the Pipeline exist in the same Git repo.
- Remote Pipeline Template and the Pipeline exist in different Git repos.
Let us see how you can use Template in each of these situations.
Remote pipeline template and the pipeline exist in the same Git repo
In order to use the Template in your Pipeline if your remote Pipeline Template and Pipeline are both present in the same Git repository, make sure your Pipeline and Template are both present in the same branch.
Remote pipeline template and the pipeline exist in different Git repos
In order to use the Template in your Pipeline if your remote Pipeline Template and Pipeline are present in different Git repositories, make sure your Template is present in the default branch of the specific repo.
Create a remote pipeline template
You can create a Stage Template from your Account, Org or Project. This topic explains the steps to create a Stage Template from the Project scope.
- In your Harness Account, go to your Project.
- In Project SETUP click Templates.
- Click New Template and then click Pipeline. The Create New Pipeline Template settings appear.
- In Name, enter a name for the Template.
- In Version Label, enter a version for the Template.
- Click Remote.
- In Git Connector, select or create a Git Connector to the repo for your Project. For steps, go to code repo connectors.
- In Repository, select your repository. If your repository isn't listed, enter its name since only a select few repositories are filled here. Create the repository in Git before entering it in Select Repository. Harness does not create the repository for you.
- In Git Branch, select your branch. If your branch isn't listed, enter its name since only a select few branches are filled here.Create the branch in your repository before entering it in Git Branch. Harness does not create the branch for you.
- Harness auto-populates the YAML Path. You can change this path and the file name.
- Click Start.
The Git connector must use the Enable API access option and TokenThe Connector must use the Enable API access option and Username and Token authentication.
Harness requires the token for API access.
Generate the token in your account on the Git provider and add it to Harness as a Secret. Next, use the token in the credentials for the Git Connector.
For GitHub, the token must have the following scopes:
Add a stage
- Click Add Stage. The Select Stage Type settings appear.
- Select Deploy. The Deploy stage type is a CD Stage that enables you to deploy any Service to your target environment.
The About Your Stage settings appear. - In Stage Name, enter a name for your Stage. Select the entity that this stage should deploy.
- In Deployment Type, click Kubernetes.
- Click Set Up Stage.
Add service details
- In Select Service, select an existing Service that you want to deploy from the Specify Service drop-down list or create a new one. You can also use fixed values runtime inputs and expressions.
- Select Continue.
- In Specify Environment, select an existing environment or add a new one.
- In Specify Infrastructure, select an existing infrastructure or add a new one. Select Continue.
The Execution Strategies settings appear.
Define execution strategies
In Execution Strategies, select the deployment strategy for your pipeline template. This topic uses the example of Rolling deployment. For more information on different execution strategies, go to deployment concepts and strategies.
Select Use Strategy.
Select Save. The Save Template to Git settings appear.
Save a remote pipeline template to Git
In Select Branch to Commit, You can select one of the following:
- Commit to an existing branch: you can start a pull request if you like.
- Commit to a new branch: enter the new branch name. You can start a pull request if you like.
Select Save. Your Remote Pipeline Template is saved to the repo branch.
Click the YAML file to see the YAML for the stage template.
Edit the YAML. For example, change the name of the template.
Commit your changes to Git.
Return to Harness and refresh the page.
A Template Updated message appears.