Overview

Local Templates can be a:

  • Copy of a system template: You can download a copy of a system template and commit it to your pipeline source repository. At this point, your template is disconnected from the centrally available template and will not be updated if the central template is updated.
    or
  • Fully customized template for the pipeline: If you do not want to use an existing template, you can create a new, fully customized YAML file in your pipeline source repository and specify the config using the template pattern. 


template: true   # required for local templates    
valuesFilePath: <relative path for values.yml> # required for local templates. DO NOT SPECIFY for system level templates

resources:
  - name: {{ .Values.GitRepo.name }}
    type: GitRepo
    configuration:
      gitProvider: {{ .Values.GitRepo.gitProvider }} 
      path: {{ .Values.GitRepo.path }}   
      branches:
        include: {{ .Values.GitRepo.branches.include }}

  - name: {{ .Values.Image.name }}
    type: Image
    configuration:
      registry: {{ .Values.artifactoryIntegration }}
      sourceRepository: {{ .Values.Image.sourceRepository }}
      imageName: {{ .Values.DockerBuild.dockerImageName }}
      imageTag: 1
      autoPull: true
  
pipelines:
  - name: {{ .Values.Pipeline.name }}
    steps:
      - name: {{ .Values.DockerBuild.name }}
        type: DockerBuild
        configuration:
          dockerFileLocation: .        # requires Dockerfile to be in root
          dockerFileName: {{ .Values.DockerBuild.dockerFileName }}
          dockerImageName: {{ .Values.DockerBuild.dockerImageName }}
          dockerImageTag: ${run_number}  # requires tag to be run number   
          inputResources:
            - name: {{ .Values.GitRepo.name }}  
          integrations:
            - name: {{ .Values.artifactoryIntegration }}

      - name: {{ .Values.DockerPush.name }}
        type: DockerPush
        configuration:
          targetRepository: {{ .Values.DockerPush.targetRepository }}
          integrations:
            - name: {{ .Values.artifactoryIntegration }}
          inputSteps:
            - name: {{ .Values.DockerBuild.name }}
          outputResources:
            - name: {{ .Values.Image.name }}

      - name: {{ .Values.Bash.name }}
        type: Bash
        configuration:
          inputResources:
            - name: {{ .Values.Image.name }}
        execution:
          onExecute:
            - echo “This is a Bash step”

In addition to the local template file, a values.yml file is required in the same repository. This file contains the values required for the local template to create the pipeline definition.

artifactoryIntegration: myArtifactoryIntegration

GitRepo:
  name: myGitRepo
  gitProvider: myGitIntegration
  path: myorg/myrepo
  branches:
    include: master

Image:
  name: myDockerImage
  sourceRepository: mySourceRepo      

Pipeline:
  name: myDockerPipeline

DockerBuild:
  name: myDockerBuild   
  dockerFileName: Dockerfile
  dockerImageName: <image name>

DockerPush:
  targetRepository: docker-local 

Bash:
  name: myBashStep

Template Functions List

Local templates support several helm chart style functions. For the full list of supported and unsupported functions, see Template Functions List.


Adding Local Templates

To add and use local templates:

  1. In your local template file (for example, pipelines.yml), set template to true and set valuesFilePath to the relative path of the values.yml file. 
    template: true
    valuesFilePath: values.yml
    Setting template to true identifies the yaml file as a local template. The combination of values.yml and pipelines.yml is parsed to create the pipeline definition and synced to create the pipeline.
  2. Go to Administration | Pipelines | Pipeline Sources.
  3. In the resulting Pipeline Sources display, click Add Pipeline Source, and then click From YAML.



  4. In the resulting Add YAML Pipeline Source page, click one of the following:
    • Single Branch
    • Multi Branch
  5.  Complete the Single/Multi Branch form: 
    • SCM Provider Integration: Click the SCM Provider Integration field and select your source control integration from the dropdown list. Only integrations that are compatible for use as a Pipeline Source will be included in the dropdown list.
    • Repository Full Name: Based on the information you have provided for the selected integration, such as API token, all the relevant repositories are listed in the Repository Full Name field. Select the path of the repository where your pipeline files are stored. If the name of the repository is not auto-fetched, enter the full name of the repository where your pipeline files are stored.
    • Branch (Single Branch only): Based on the SCM provider and Repository Full Name you have provided, all the available branches are automatically fetched (for example, main). Select the required branch. If the name of the branch is not auto-fetched, enter the name of the branch.
    • Exclude Branch (Multi Branch only): Specify the Exclude Branch Pattern as a regular expression for the matching branch names to exclude.
    • Include (Multi Branch only): Specify the Include Branch Pattern as a regular expression for the matching branch names to include.
    • Pipeline Config File Filter: Enter pipelines.yml.
  6. Click Create Source to complete adding the Pipeline Source.