DOC_INDEX
THEME
DOCS/Functions/assert

assert

Validate conditions using Go template expressions or JavaScript

Validate conditions using Go template expressions or JavaScript. Fails the step when the condition evaluates to false.

Parameters

ParameterTypeRequiredDescription
funcstringyesMust be assert
args.conditionstringyesExpression to evaluate. Supports Go templates ({{ }}) and JavaScript syntax.
args.descstringnoError message displayed when assertion fails

Dual Syntax

OrchStep detects the syntax automatically:

PatternSyntaxExample
{{ ... }}Go Template'{{ eq vars.env "prod" }}'
No {{ }}JavaScript'vars.env === "prod"'

Return Values

FieldTypeDescription
result.passedboolWhether the assertion passed
result.valueanyThe evaluated condition value

Examples

Basic Assertion

steps:
  - name: verify_build
    func: assert
    args:
      condition: '{{ eq steps.build.exit_code 0 }}'
      desc: "Build must succeed before deployment"

Go Template Comparisons

steps:
  - name: check_version
    func: assert
    args:
      condition: '{{ ne vars.version "" }}'
      desc: "Version must not be empty"

  - name: check_count
    func: assert
    args:
      condition: '{{ gt vars.replicas 0 }}'
      desc: "Must have at least 1 replica"

  - name: check_combined
    func: assert
    args:
      condition: '{{ and (eq vars.env "prod") (gt vars.replicas 2) }}'
      desc: "Production requires 3+ replicas"

String Matching (Go Templates)

steps:
  - name: check_output
    func: assert
    args:
      condition: '{{ contains "SUCCESS" steps.build.output }}'
      desc: "Build output must contain SUCCESS"

  - name: check_prefix
    func: assert
    args:
      condition: '{{ hasPrefix vars.version "v" }}'
      desc: "Version must start with v"

  - name: check_regex
    func: assert
    args:
      condition: '{{ regexMatch "v[0-9]+\\.[0-9]+" vars.version }}'
      desc: "Version must match semver pattern"

JavaScript Syntax

steps:
  - name: check_status
    func: assert
    args:
      condition: 'steps.api_call.status_code >= 200 && steps.api_call.status_code < 300'
      desc: "API call must return 2xx status"

  - name: check_string
    func: assert
    args:
      condition: 'steps.build.output.includes("SUCCESS")'
      desc: "Build must succeed"

Aggregation Helpers (JavaScript)

For loop outputs that produce arrays, use built-in aggregation helpers:

steps:
  - name: all_succeeded
    func: assert
    args:
      condition: 'all(steps.batch_requests.outputs, "status_code", 200)'
      desc: "All batch requests must return 200"

  - name: check_count
    func: assert
    args:
      condition: 'count(steps.results.outputs) === 5'
      desc: "Should have exactly 5 results"

  - name: check_average
    func: assert
    args:
      condition: 'avg(steps.perf_tests.outputs, "response_time") < 500'
      desc: "Average response time must be under 500ms"

Available helpers:

HelperPurposeExample
first(array)First elementfirst(steps.items.outputs).id
last(array)Last elementlast(steps.batch.outputs).status
at(array, index)Safe index accessat(steps.results.outputs, 2).score
all(array, field, value)All items matchall(steps.tests.outputs, "passed", true)
any(array, field, value)Any item matchesany(steps.checks.outputs, "failed", true)
count(array [, field, value])Count itemscount(steps.items.outputs, "valid", true)
pluck(array, field)Extract field valuespluck(steps.users.outputs, "email")
sum(array, field)Sum numeric fieldsum(steps.sales.outputs, "amount")
avg(array, field)Average numeric fieldavg(steps.times.outputs, "duration")

Post-Deployment Verification

tasks:
  verify_deploy:
    steps:
      - name: health_check
        func: http
        args:
          url: "https://{{ vars.env }}.example.com/health"
          method: GET

      - name: assert_healthy
        func: assert
        args:
          condition: '{{ eq steps.health_check.status_code 200 }}'
          desc: "Service must be healthy after deployment"

      - name: assert_version
        func: assert
        args:
          condition: 'steps.health_check.data.version === vars.expected_version'
          desc: "Deployed version must match expected version"

Run it

orchstep run verify_deploy