Deploy Workflow Definitions

Workflow Definitions

Workflow definitions are XML files that specify a process using the BPMN (Business Process Model and Notation) schema with Zeebe extensions.

You can create and edit these files using the graphical Zeebe modeler.

Deploy workflow definition files

The method ZBClient.deployWorkflow can take a string or an array of strings, where each string is a file path to a BPMN file containing a workflow definition to deploy:

import { ZBClient } from 'zeebe-node'
import path from 'path'

const zbc = new ZBClient()

async function deployMyWorkflowDefinition(filepaths: string | string[]) {
  const res = await zbc.deployWorkflow(filepaths)
  console.log(res)
  return res
}

deployMyWorkflowDefinition(
  path.join(
    __dirname, 
    '..', 
    'bpmn', 
    'my-workflow.bpmn'
))
const { ZBClient } = require('zeebe-node')
const path = require('path')

const zbc = new ZBClient()

async function deployMyWorkflowDefinition(filepaths) {
  const res = await zbc.deployWorkflow(filepaths)
  console.log(res)
  return res
}

deployMyWorkflowDefinition(
  path.join(
    __dirname, 
    '..', 
    'bpmn', 
    'my-workflow.bpmn'
))

The deployWorkflow command returns a DeployWorkflowResponse. This has an array of WorkflowMetadata, containing information about the workflow definitions deployed.

The method will throw if any of the workflow definitions are malformed - in this case none are deployed. @TODO - verify

Note on versioning: Re-deploying a workflow definition does not create a new version of that workflow definition in the broker cluster, unless the definition has been modified - in which case a new version is created.

Deploy a workflow definition from an in-memory buffer

ZBClient.deployWorkflow can also deploy a workflow definition from an in-memory buffer.

This is useful if, for example, you perform template processing on a workflow definition after loading it from a file, before deploying it. See here for an example of doing that with micromustache.

import { ZBClient } from 'zeebe-node'
import { transformWfd } from './my-workflow-transformer'
import fs from 'fs';
import path from 'path'

const zbc = new ZBClient()

async function deployMyWorkflowDefinition(filepath: string) {
  const workflow = fs.readFileSync(filepath, 'utf-8')
  const xFormedWfd = transformWfd(workflow)
  const res = await zbc.deployWorkflow({
    definition: Buffer.from(xFormedWfd),
    name: path.basename(filepath)
  })
  console.log(res)
  return res
}

deployMyWorkflowDefinition(
  path.join(
    __dirname, 
    '..', 
    'bpmn', 
    'my-workflow.bpmn'
))
const { ZBClient } = require('zeebe-node')
import { transformWfd } from './my-workflow-transformer'
import fs from 'fs';
const path = require('path')

const zbc = new ZBClient()

async function deployMyWorkflowDefinition(filepath: string) {
  const workflow = fs.readFileSync(filepath, 'utf-8')
  const xFormedWfd = transformWfd(workflow)
  const res = await zbc.deployWorkflow({
    definition: Buffer.from(xFormedWfd),
    name: path.basename(filepath)
  })
  console.log(res)
  return res
}

deployMyWorkflowDefinition(
  path.join(
    __dirname, 
    '..', 
    'bpmn', 
    'my-workflow.bpmn'
))