Introduction
Users frequently find a situation when a job creates a result which should be forwarded to subsequent jobs in a workflow.
Passing Variables
Shell Jobs
Download Example for Unix (.json upload): pdwVariablesPassingUnix.workflow.json
Download Example for Windows (.json upload): pdwVariablesPassingWindows.workflow.json
First Job: Write Variables
Shell jobs can pass results to subsequent jobs:
- by creating a key/value pair with the syntax:
key=value
. - The key/value pair is appended to a temporary file which is provided by JS7 and that is indicated by the JS7_RETURN_VALUES environment variable.
- The key provided is the name of the order variable which can be used by subsequent jobs.
- If the variable does not yet exist it will be created on-the-fly.
- If the variable exists then the value will be overwritten
The job script implementation looks like this:
#!/bin/bash # create results first_result=$RANDOM second_result=$RANDOM # pass results from a key/value pair that is appended to a temporary file provided by JS7 echo "firstResult=$first_result" >> $JS7_RETURN_VALUES echo "secondResult=$second_result" >> $JS7_RETURN_VALUES
@rem create results @set first_result=%RANDOM% @set second_result=%RANDOM% @rem pass results from a key/value pair that is appended to a temporary file provided by JS7 @echo firstResult=%first_result% >> %JS7_RETURN_VALUES% @echo secondResult=%second_result% >> %JS7_RETURN_VALUES%
# create results $firstResult=Get-Random $secondResult=Get-Random # pass results from a key/value pair that is appended to a temporary file provided by JS7 "firstResult=$first_result" | Out-File -File $env:JS7_RETURN_VALUES -Append -Encoding ASCII "secondResult=$second_result" | Out-File -File $env:JS7_RETURN_VALUES -Append -Encoding ASCII
Second Job: Read Variables
Shell jobs access order variables and order variables from a mapping to environment variables.
- The JOC Cockpit GUI allows the mapping to be added per job from the right lower corner with the Environment Variables sub-tab.
- The mapping includes free choice of the name of an environment variable which is used in the job script and to assign an existing order variable.
- The spelling of variable names is case-sensitive.
The job script implementation looks like this:
#!/bin/bash # read results echo "FIRST_RESULT = $FIRST_RESULT" echo "SECOND_RESULT = $SECOND_RESULT"
@rem read results @echo FIRST_RESULT = %FIRST_RESULT% @echo SECOND_RESULT = %SECOND_RESULT%
Considerations
Scope of Order Variables
The examples above create order variables on-the-fly. Such variables can be overwritten by any job or instruction in a workflow.
However, if variables are declared with the workflow, then they are considered arguments which cannot be overwritten:
- Clicking in the background of the middle panel without selecting any object such as a job, will cause the workflow properties to be shown in the right hand panel.
- Workflow properties allow variables to be added which:
- can carry no default value: Such variables are considered mandatory and values have to be added when submitting orders.
- can carry a default value: Such variables leave it up to the order to provide a value which would overwrite the default value.
If a variable is declared at workflow level then it cannot be overwritten by subsequent jobs.
Historic Outcome of Order Variables
The examples above create order variables on-the-fly. Such variables can be overwritten by any job or instruction in a workflow..
- JS7 keeps track of the historic outcome of variables with an order's position in the workflow and restores values if a job is repeated. You can make the second job fail and use
- the Resume operation offered by the JOC Cockpit GUI allows the job to be rerun with the same order variable values as before.
- the Resume parameterized operation offered by the JOC Cockpit GUI allows order variables to be modified before rerunning the job.
This operation makes a popup window appear that looks like this:
- Most recent values of order variables are displayed and can be modified.
- The
returnCode
is a built-in variable that shows the historic value of the predecessor job's return code.
Modifications include changing the values of order variables and modifying the order's position in the workflow:
- Drag & Drop the order by holding the red bullet of the failed order and move the order to a different position.
- Drag & Drop operations are limited within a logical scope:
- they allow selection of a position within a sequence of jobs and instructions in a workflow.
- they do not allow jumping into a JS7 - Fork-Join Instruction or other instructions that check an initial condition which might not be met by the current order.