Skip to content
Talk to our solutions team

Pass arguments into a script

Values from the command line reaching your script, with the types you expect.

A script with its inputs hard-coded is a script you edit to test. Parameterising it turns one file into something you can run against every case you care about.

Without thisWith this
Edit the file, run, edit backRun it again with different arguments
Testing three cases means three copiesOne file, three commands
The script cannot move into a flow unchangedThe same calling convention as a flow’s script: task

A flow takes its inputs as run variables, set with -v or loaded from a file with -e:

name: order
vars:
name: widget
qty: 1
tasks:
- name: total
print:
message: "{{name}} x {{qty}}"
Terminal window
kis flow -f order.yaml -v name=widget -v qty=3
widget x 3

Declaring them under vars: with defaults is what makes the flow self-documenting: the values someone will want to change are at the top, not buried in a node.

Note total: 30, not "33333333333". Script arguments are JSON-parsed best-effort, so 3 arrives as a number and arithmetic works. A value that does not parse as JSON falls back to a string, which is why widget arrives as text without quoting.

That fallback is the thing to watch: true, null and 12 become their JSON types, so a product code that happens to be all digits arrives as a number. Quote it if you need the string — '"0012"'.

The repeatable --args flag does the same thing and combines with positionals:

Terminal window
kis script run order.js --args widget --args 3

This is the one that catches people moving between them. A flow template writes the value in literally, so quoting in the payload is how you choose the JSON type:

payload: '{"name":"{{name}}","qty":{{qty}}}'

{{name}} is quoted so it lands as a string; {{qty}} is not, so it lands as a number. Get that wrong and the receiving API sees "3" where it wanted 3.

Both surfaces separate what this run is about from where it is running.

Everything is a run variable, so the separation is a convention rather than a mechanism: put the values that change per run at the top of vars:, and load the rest from an environment file.

Terminal window
kis flow -f deploy.yaml -e production.yaml -v service=api

-e carries the environment; -v carries this run’s subject. Keeping them in separate places is what lets one flow serve every environment.

A node writes into the run with setvar, and later nodes read it back with {{ }}:

list: true
tasks:
- name: count
shell:
script: ls -1 | wc -l
setvar: files
- name: report
print:
message: "{{files}} files"

The value outlives the node. Anything after it in the run can read {{files}}.

function handler(a, b) {
return a + b;
}
Terminal window
kis script run math.js --func handler 3 4 --debug
Result: 7

Useful when one file holds several related operations and you want to exercise one.

InputFlowScript
The data the job acts on-v k=vpositional arguments
Ambient configuration-e env.yaml--vars, --env
One of several operations in a file-n <flow-name>--func
Tenancy identityrun context--cpet customer,product,environment,tenant

Print the arguments back before trusting the types:

function main(a, b) {
return { a: a, typeA: typeof a, b: b, typeB: typeof b };
}

That one line settles every “why is my number a string” question.