Explains Argo WorkflowTemplates and ClusterWorkflowTemplates as reusable workflow recipes, how to define and reference them with templateRef or workflowTemplateRef to share and standardize CI/CD steps.
Think of a WorkflowTemplate as a reusable recipe for Argo Workflows. Instead of copying and pasting the same manifest (for example, a build step or a test container) into every workflow, define it once as a WorkflowTemplate and reference it from many workflows. This centralizes maintenance, enforces consistency, and reduces duplication.
A WorkflowTemplate stores common templates in a namespace so teams can share and reuse steps like functions from a library. Use templates to standardize CI/CD tasks such as builds, tests, and deployments.
Defining a WorkflowTemplate is the same as defining a Workflow, except the resource kind is WorkflowTemplate. That tells Argo to store the definition as a reusable template rather than executing it immediately.Example WorkflowTemplate (cowsay):
Use when you want to execute the whole WorkflowTemplate as a workflow
workflowTemplateRef: { name: cowsay-template }
Example: calling a single template from a WorkflowTemplate using templateRef
Copy
apiVersion: argoproj.io/v1alpha1kind: Workflowmetadata: generateName: use-single-template-spec: entrypoint: my-custom-workflow templates: - name: my-custom-workflow steps: - - name: first-step templateRef: name: cowsay-template # name of the WorkflowTemplate template: cowsay # name of the template inside the WorkflowTemplate arguments: parameters: - name: message value: "I called this from another workflow!"
Example: running the whole WorkflowTemplate using workflowTemplateRef
Copy
apiVersion: argoproj.io/v1alpha1kind: Workflowmetadata: generateName: run-whole-template- namespace: argospec: arguments: parameters: - name: message value: "Hello from a WorkflowTemplate!" workflowTemplateRef: name: cowsay-template
A ClusterWorkflowTemplate is the cluster-scoped equivalent of WorkflowTemplate. It is not tied to a namespace and is available cluster-wide — a good fit for platform teams that must provide approved, central templates to multiple namespaces.Example ClusterWorkflowTemplate:
Because ClusterWorkflowTemplate is cluster-scoped, metadata does not include a namespace.Referencing a ClusterWorkflowTemplate from a namespaced Workflow requires setting the clusterScope flag to true.Example: calling a single template from a ClusterWorkflowTemplate via templateRef (clusterScope: true)
Copy
apiVersion: argoproj.io/v1alpha1kind: Workflowmetadata: generateName: use-single-cluster-template-spec: entrypoint: my-custom-workflow templates: - name: my-custom-workflow steps: - - name: first-step templateRef: name: global-utility-templates # ClusterWorkflowTemplate name template: global-cowsay # template name inside the ClusterWorkflowTemplate clusterScope: true # required when referencing a cluster-scoped template arguments: parameters: - name: message value: "I called this from a ClusterWorkflowTemplate!"
Example: running the whole ClusterWorkflowTemplate via workflowTemplateRef (clusterScope: true)
When referencing cluster-scoped templates (ClusterWorkflowTemplate), always set clusterScope: true in templateRef or workflowTemplateRef. ClusterWorkflowTemplates are not namespaced, so this flag tells Argo the reference is to a cluster-level resource.