agentleFS
dungnotnulldungnotnull/hybrid-harness-chaos-process-prm/skills/s09-template-library/SKILL.md

harness-template-library

Skill19 starsChanged 6 months agoMITView on GitHub

Create, version, and govern reusable Harness templates (pipeline templates, stage templates, step templates, step group templates) to enforce standards across teams. Use this skill whenever the user mentions Harness templates, reusable stages, shared step groups, template library, template versioning, template enforcement, or when multiple teams need to follow the same pipeline pattern. Also trigger when a user wants to "templatize" an existing pipeline or reduce copy-paste across team pipelines.

  • Sends data out

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When Harness AI is unavailable: Use static pipeline templates from s09 Template Library and manual YAML construction following Harness …

    line 439

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Harness Template Library

Purpose

Build a governed library of reusable pipeline building blocks that enforce engineering standards, eliminate copy-paste drift, and allow teams to compose pipelines from pre-approved, versioned templates.


Input Contract

InputSourceRequired
Pipeline design patternss04 outputYes
Security scan requirementss01 PRD or userNo
Approval gate requirementss01 (compliance needs)Yes
Notification preferencess02 taste (communication)No
Service team structuress05 outputNo

Output Contract

OutputDestinationFormat
Deploy stage template.commandcode/artifacts/template-deploy.yamlYAML
Security scan step group template.commandcode/artifacts/template-security.yamlYAML
Approval stage template.commandcode/artifacts/template-approval.yamlYAML
Notification step group template.commandcode/artifacts/template-notify.yamlYAML
Template enforcement OPA policys22 (governance)Rego
Template version changelog.commandcode/artifacts/template-changelog.mdMarkdown

Prerequisites

  • Harness account with Template Library access
  • Engineering standards documented (what must be identical across all pipelines)
  • RBAC roles defined (who can create/modify templates vs use them)

Template Hierarchy

Account-level templates   → Shared across ALL orgs and projects
    └── Org-level templates       → Shared across all projects in org
            └── Project-level templates    → Used within one project

Template Types:
├── Pipeline Template      → Entire pipeline as a template
├── Stage Template         → One stage (CI, CD, Approval, etc.)
├── Step Template          → One step (Run, ShellScript, etc.)
└── Step Group Template    → A group of steps as a unit

Template Versioning Strategy

<template-identifier>
├── v1 — Stable (in use by 20+ pipelines)
├── v2 — Stable (new default)
└── v3 — Beta (testing phase)

Versioning rules:
- Patch (1.0 → 1.1): Non-breaking — add optional fields, fix bugs
- Minor (1.x → 2.0): Breaking — remove fields, change required inputs
- Always keep v_previous stable for 30 days after new version release
- Deprecation: set isStable: false, add deprecation notice in description

Essential Template Catalog

Template 1 — Standard Deploy Stage

template:
  name: Standard K8s Deploy Stage
  identifier: standard_k8s_deploy_stage
  versionLabel: "2.0"
  type: Stage
  orgIdentifier: <ORG_ID>
  tags:
    managed-by: hcprm
    template-type: deploy
  spec:
    type: Deployment
    spec:
      deploymentType: Kubernetes
      service:
        serviceRef: <+input>
        serviceInputs: <+input>
      environment:
        environmentRef: <+input>
        infrastructureDefinitions: <+input>
      execution:
        steps:
          - step:
              name: Pre-Deploy Health Check
              identifier: pre_deploy_health_check
              type: ShellScript
              spec:
                shell: Bash
                source:
                  type: Inline
                  spec:
                    script: |
                      echo "Pre-deploy health check for env: <+env.name>"
                      kubectl get nodes --no-headers | awk '{print $2}' | grep -v Ready && \
                        echo "WARNING: unhealthy nodes detected" || echo "All nodes Ready"
                onDelegate: true
          - step:
              name: Deploy
              identifier: deploy
              type: K8sRollingDeploy
              spec:
                skipDryRun: false
                pruningEnabled: true
          - step:
              name: Verify Deployment
              identifier: verify_deployment
              type: Verify
              timeout: 30m
              spec:
                isMultiServicesOrEnvs: false
                type: Rolling
                monitoredServiceRef: <+input>
                sensitivity: MEDIUM
                duration: 10m
                failOnNoAnalysis: true
        rollbackSteps:
          - step:
              name: Rollback
              identifier: rollback
              type: K8sRollingRollback
              spec: {}
          - step:
              name: Notify Rollback
              identifier: notify_rollback
              type: ShellScript
              spec:
                shell: Bash
                source:
                  type: Inline
                  spec:
                    script: |
                      curl -X POST "<+pipeline.variables.slackWebhook>" \
                        -H "Content-Type: application/json" \
                        -d '{"text": "🔴 ROLLBACK: <+service.name> in <+env.name>"}'
                onDelegate: true

Template 2 — Security Scan Step Group

template:
  name: Security Scan Step Group
  identifier: security_scan_step_group
  versionLabel: "1.2"
  type: StepGroup
  orgIdentifier: <ORG_ID>
  description: "SAST + container scan + secrets scan — required for all CI pipelines"
  tags:
    managed-by: hcprm
    compliance: required
  spec:
    steps:
      - step:
          name: SAST Scan (Semgrep)
          identifier: sast_semgrep
          type: Run
          spec:
            connectorRef: account.dockerhub
            image: returntocorp/semgrep:latest
            command: |
              semgrep \
                --config=p/owasp-top-ten \
                --config=p/security-audit \
                --json \
                --output=/shared/semgrep-results.json \
                .
              # Fail on HIGH severity findings
              python3 -c "
              import json, sys
              with open('/shared/semgrep-results.json') as f:
                  results = json.load(f)
              high = [r for r in results['results'] if r['extra']['severity'] == 'ERROR']
              if high:
                  print(f'FAIL: {len(high)} HIGH severity SAST findings')
                  sys.exit(1)
              print('PASS: No HIGH severity SAST findings')
              "
      - step:
          name: Container Scan (Trivy)
          identifier: container_scan_trivy
          type: Run
          spec:
            connectorRef: account.dockerhub
            image: aquasec/trivy:latest
            command: |
              trivy image \
                --exit-code 1 \
                --severity HIGH,CRITICAL \
                --no-progress \
                <+artifact.image>:<+artifact.tag>
      - step:
          name: Secrets Scan (Gitleaks)
          identifier: secrets_scan_gitleaks
          type: Run
          spec:
            connectorRef: account.dockerhub
            image: zricethezav/gitleaks:latest
            command: |
              gitleaks detect \
                --source . \
                --report-format json \
                --report-path /shared/gitleaks-report.json \
                --exit-code 1

Template 3 — Production Approval Stage

template:
  name: Production Approval Stage
  identifier: production_approval_stage
  versionLabel: "1.0"
  type: Stage
  orgIdentifier: <ORG_ID>
  description: "Mandatory approval gate before any production deployment"
  tags:
    managed-by: hcprm
    compliance: required
  spec:
    type: Approval
    spec:
      execution:
        steps:
          - step:
              name: JIRA Change Request
              identifier: jira_change_request
              type: JiraCreate
              spec:
                connectorRef: <+input>
                projectKey: CHG
                issueType: Change Request
                fields:
                  - name: Summary
                    value: "Deploy <+service.name> <+artifact.tag> to production"
                  - name: Description
                    value: |
                      **Service**: <+service.name>
                      **Version**: <+artifact.tag>
                      **Pipeline**: <+pipeline.name>
                      **Execution**: <+pipeline.executionId>
          - step:
              name: Production Sign-off
              identifier: production_signoff
              type: HarnessApproval
              spec:
                approvalMessage: |
                  **Production Deployment Approval Required**

                  Service: <+service.name>
                  Version: <+artifact.tag>
                  Environment: Production
                  Initiated by: <+pipeline.triggeredBy.name>

                  Please verify:
                  ✅ Staging verification passed
                  ✅ Change request approved
                  ✅ Deployment window confirmed
                  ✅ On-call engineer aware
                includePipelineExecutionHistory: true
                approvers:
                  minimumCount: 2
                  disallowPipelineExecutor: true
                  userGroups:
                    - account.SRE_Team
                    - account.Engineering_Leads
                approverInputs:
                  - name: changeRequestId
                    defaultValue: ""
                  - name: onCallEngineer
                    defaultValue: ""
                autoApproval:
                  action: REJECT
                  scheduledDeadline:
                    timeZone: UTC
                    time: "23:00"

Template 4 — Notification Step Group

template:
  name: Deployment Notifications
  identifier: deployment_notifications
  versionLabel: "1.0"
  type: StepGroup
  spec:
    steps:
      - step:
          name: Slack Notify Start
          identifier: slack_notify_start
          type: ShellScript
          spec:
            shell: Bash
            source:
              type: Inline
              spec:
                script: |
                  curl -X POST "<+pipeline.variables.slackWebhook>" \
                    -H "Content-Type: application/json" \
                    -d '{
                      "text": "🚀 Deploying *<+service.name>* `<+artifact.tag>` to *<+env.name>*",
                      "attachments": [{
                        "color": "warning",
                        "fields": [
                          {"title": "Triggered by", "value": "<+pipeline.triggeredBy.name>", "short": true},
                          {"title": "Pipeline", "value": "<+pipeline.executionId>", "short": true}
                        ]
                      }]
                    }'
            onDelegate: true

Using Templates in Pipelines

pipeline:
  stages:
    - stage:
        name: Security Scans
        identifier: security_scans
        type: CI
        spec:
          execution:
            steps:
              # Reference step group template
              - stepGroup:
                  name: Security Scans
                  identifier: security_scans_group
                  template:
                    templateRef: org.security_scan_step_group  # org. prefix = org-level
                    versionLabel: "1.2"

    - stage:
        # Reference stage template
        template:
          templateRef: org.standard_k8s_deploy_stage
          versionLabel: "2.0"
          templateInputs:
            type: Deployment
            spec:
              service:
                serviceRef: payment_service
              environment:
                environmentRef: production
                infrastructureDefinitions:
                  - identifier: payment_prod_infra

    - stage:
        # Reference approval stage template
        template:
          templateRef: org.production_approval_stage
          versionLabel: "1.0"
          templateInputs:
            type: Approval
            spec:
              execution:
                steps:
                  - step:
                      identifier: jira_change_request
                      template:
                        templateInputs:
                          spec:
                            connectorRef: jira_connector

Template Governance

Enforce Template Usage via OPA

package template_enforcement

# CD stages must use the standard deploy template (not custom stages)
deny["CD stage must use org.standard_k8s_deploy_stage template"] {
  stage := input.pipeline.stages[_].stage
  stage.type == "Deployment"
  not uses_approved_template(stage)
}

uses_approved_template(stage) {
  stage.template.templateRef == "org.standard_k8s_deploy_stage"
}

AI Agent Integration

Autonomy Level

AspectLevelDescription
CurrentL1AI identifies reusable patterns from existing pipelines
TargetL2AI generates and maintains template library

Harness AI Agent

Agent: Harness AI DevOps Agent Capabilities:

  • Pattern recognition across pipelines
  • Template extraction and generalization
  • Template version management

Human Gates

  • Template publication
  • Template deprecation decisions

Fallback

When Harness AI is unavailable: Use static pipeline templates from s09 Template Library and manual YAML construction following Harness schema documentation.


Success Criteria

  • All 4 core templates published at org-level
  • All new pipelines referencing templates (not inline stages)
  • Template versioning strategy documented and communicated
  • OPA policy enforcing template usage active
  • Template changelog maintained per version
  • At least 3 team pipelines migrated from inline stages to templates

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.