You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Introduction

Users frequently find a situation when a job creates some result that 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 that is provided by JS7 and that is indicated by the JS7_RETURN_VALUES environment variable.
  • The key provided is the name of the workflow variable that can be used by subsequent jobs.
    • If the variable does not yet exist then it is created on-the-fly.
    • If the variable exists then the value is overwritten


The job script implementation looks like this:

Example of a Unix Shell job passing variables
#!/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
Example of a Windows Shell job passing variables
@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%

Second Job: Read Variables

Shell jobs access workflow variables and order variables from a mapping to environment variables.

  • The JOC Cockpit GUI offers to add the mapping per job from the right lower corner with the sub-tab Environment Variables.
  • The mapping includes to freely choose the name of an environment variable that is used in the job script and to assign an existing workflow variable or order variable.
  • The spelling of variable names is case-sensitivee


The job script implementation looks like this:

Example of a Unix Shell job reading variables
#!/bin/bash

# read results
echo "FIRST_RESULT = $FIRST_RESULT"
echo "SECOND_RESULT = $SECOND_RESULT"
Example of a Windows Shell job passing variables
@rem read results
@echo FIRST_RESULT = %FIRST_RESULT%
@echo SECOND_RESULT = %SECOND_RESULT%
  • No labels