There could be scenarios where you want to develop and test templates before they are released for general consumption. This helps in reducing the lifecycle of developing and using a template, and enables you to use any pipeline's YAML as a template. Templates can be developed and tested from your local SCM repository and released to a wider audience only when you are ready to do so.
A pipeline YAML can be denoted as a template under development by adding a template definition to the top of the pipeline YAML definition. In the definition, define the name
, namespace
, and version
of the template. In addition, a boolean tag called development
is used to identify the development stage of the template. During sync, Pipelines recognizes this as a template that is in development and adds the template. When the template is ready to be released, set this tag as false
and use the pre-loaded template called PublishTemplate to release the template and publish it to Artifactory.
To develop and test a system template:
In your SCM repository, create a new directory named
.jfrog-pipelines
.In the directory, create three new files:
templateDefinition.yml
<pipeline_file>.yml
values.yml
(optional)
templateDefinition.yml: This is the template definition YAML file. It is recommended that you name this file
templateDefinition.yml
. This will help when publishing from the same folder and also helps in differentiating the template file from other pipeline YAML files, especially when it needs to be moved to another repository for publishing.Add the following in the
templateDefinition.yml
file:template: namespace: <namespace> name: <template_name> version: <template_version> development: boolean # optional; default is true
Example
template: namespace: myNamespace name: myTemplate version: 1.0.0 development: true
Where:
template
keyword denotes that the pipeline definition is a template and not a regular pipeline YAML.namespace
is the namespace used for storing the template in Artifactory.name
is the name used for storing the template in Artifactory.version
is the version of the template.development
is a boolean. Default value istrue
, which denotes that the template is in development mode and not ready for release. When the template is ready for release, set this asfalse
.
<pipeline_file>.yml: This file contains your pipeline definition and can have any name.
Add the following lines to the top of your
<pipeline_file>.yml
file:valuesFilePath: ./values.yml include: template: <namespace>/<name>/<version>
Example
valuesFilePath: ./values.yml include: template: myNamespace/myTemplate/1.0.0
Where:
namespace
is the namespace used for storing the template in Artifactory.name
is the name used for storing the template in Artifactory.version
is the version of the template.valuesFilePath
is optional. Add this only if you are using a values.yml file.
values.yml: While this is optional, it is recommended to use a values file with templates. Update the
values.yml
file to include the values required for the template you are using.While the template is still under development and not ready to be released, in the
templateDefinition.yml
file set thedevelopment
totrue
.In the JFrog Platform, go to Administration → Pipelines → Pipeline Sources and add the pipeline as a pipeline source. For more information, see Adding a Pipeline Source.
After your Pipeline Source syncs successfully, you can view the newly added pipeline by navigating to My Pipelines on the left navbar and clicking Pipelines → My Pipelines.
Go to Application → Pipelines → My Pipelines → All Pipelines and run the pipeline.
Release Templates
When the development on a template is complete and it is ready to be released:
In the
templateDefinition.yml
file, setdevelopment
tofalse
.Perform the steps outlined in this section to release the template.
When released, the template is available in Artifactory and can be viewed in the Templates UI page.