Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
outlinh1. true
outlinh1. true
1printablefalse
2stylh1. none
3indent20px

...

Accessing parameters in shell scripts

  • Environment variables are used to make job Job and order parameters accessible are exposed as environment variables to shell scripts.
  • Environment variables are named using a predefined prefix and the name of the original parameter: 
    • The default value for the environment variable prefix is is SCHEDULER_PARAM_ 
    • Environment variable names are provided with uppercase letters.
    • For example, the job a parameter param1 is can be accessed by the environment variable SCHEDULER_PARAM_PARAM1environment variable.
    • Environment variables are used with uppercase letters.
    • If the SCHEDULER_PARAM_ prefix is not to be used for the environment variables and instead the parameter names themselves then the following setting can be added to the ./config/scheduler.xml file:

      Code Block
      languagexml
      <params>
          <param name="scheduler.variable_name_prefix" value="*NONE"/>
          ...
      </param>

      (info) Note that: there is a risk of JobScheduler overwriting already existing environment variables with new ones of the same name that have been derived from job or order parameters if a prefix such as SCHEDULER_PARAM_ is not used.

...

Examples

The following two examples show a task parameter defined in a job <param> tag can be called in a shell script.

Code Block
languagexml
titleExample for Windows showing how a task parameter can be used in a shell script
collapsetrue
 <job>
    <params>
        <param name="param1"  value="Test"/>
    </params>
    <script language="shell">
        <![CDATA[
 rem This is an example shell script to show the use of parameters
 echo Param1 has the value %SCHEDULER_PARAM_PARAM1%
        ]]>
    </script>
    <run_time/>
 </job>
Code Block
languagexml
titleExample for Unix showing how a task parameter can be used in a shell script
collapsetrue
 <job>
    <params>
        <param name="param1" value="Test"/>
    </params>
    <script language="shell">
        <![CDATA[
 # This is an example shell script to show the use of parameters
 echo "Param1Parameter param1 has the value $SCHEDULER_PARAM_PARAM1"
        ]]>
    </script>
    <run_time/>
 </job

...

If you want to use parameters as command line arguments for a script then just add the environment variables as arguments in the command line:

Code Block
languagebash
titleExample for command line (Unix)
  anyshellscript.sh $SCHEDULER_PARAM_PARAM1 $SCHEDULER_PARAM_PARM2 ...

Passing parameters to subsequent shell jobs in a job chain

  • JobScheduler allows the creation or overwriting of order parameters for subsequent jobs in a job chain.
  • With every change of status in job chains JobScheduler parses a temporary file for name=/value pairs after termination of each job in a job chain.
    • The name of the this temporary file is available with held in the environment variable SCHEDULER_RETURN_VALUES environment variable.
    • The name/value pairs are automatically added as order parameters.
    • A parameter set in one job shell script can be written to this temporary file and made available to subsequent jobs using the following (for Windows):
      • myParam=myValue >> %SCHEDULER_RETURN_VALUES%
    • A task parameter set in one job can be written to this temporary file and thereby made available to subsequent jobs in a job chain using the following (for Windows):
      • myParam=%SCHEDULER_PARAM_MYPARAM% >> %SCHEDULER_RETURN_VALUES%
    • Such parameters are accessible in subsequent job using the following (for Windows):
      • echo myParam = %SCHEDULER_PARAM_MYPARAM%

The following code blocks show two jobs that demonstrate the setting and retrieval of shell script parameters in a job chain:.

Code Block
languagexml
titleExample for First Job
 <job order="yes"
     stop_on_error="no" name="job1_shell_with_parameter_set">
    <params>
        <param name="param1" value="Value1-Job1" />
        <param name="param2" value="TestValue2-Job1" />
    </params>
    <script language="shell">
        <![CDATA[
 rem This is ana examplesample shell script to demonstrate the usesetting of parameters 
echo param1 = %SCHEDULER_PARAM_PARAM1%
echo param2 newParam=an example = %SCHEDULER_PARAM_PARAM2% 
 
rem creating order parameters for subsequent jobs
echo param2 = some-other-value >> %SCHEDULER_RETURN_VALUES%
echo param3 = Value3 >> %SCHEDULER_RETURN_VALUES%
        ]]>
    </script>
    <run_time/>
 </job>
Code Block
languagexml
titleExample for Second Job
 <job order="yes" stop_on_error="no" name="job2_shell_with_parameter_get">
    <params>
        <param name="param1" value="Value1-Job2" />
        <param name="param2" value="TestValue2-Job2" />
    </params>
    <script language="shell">
        <![CDATA[
echo param1 has the value: %SCHEDULER_PARAM_PARAM1%
echo param2 has the value: %SCHEDULER_PARAM_PARAM2%
echo newParamparam3 has the value: %SCHEDULER_PARAM_NEWPARAM%PARAM3%
        ]]>
    </script>
    <run_time/>
 </job>

 

The job chain for the two example shell jobs is listed below:

Code Block
languagexml
titleExample for Job Chain
collapsetrue
 <job_chain>
    <job_chain_node state="100"
                    job="job_samplejob1_shell_with_parameter_set"
                    next_state="200"
                    error_state="error"/>
    <job_chain_node state="200"
                    job="job_sample_shelljob2_shell_with_parameter_get"
                    next_state="success"
                    error_state="error"/>
    <job_chain_node state="success"/>
    <job_chain_node state="error"/>
 </job_chain>

...

Example Behavior

The screen shot below shows the log file for the example order and the values for the environment variables.

Image Added

The log file shows that:

  • The param1 task parameters set in both the first and second jobs are only valid within the respective jobs.
  • The param2 task parameter set in the first job and which is forwarded as an environment variable to the second job overwrites the param2 task parameter set in the second job.
  • The param3 shell script parameter set in the shell script in the first job is passed to the script in the second job.

Example Download

The example described above can be downloaded from the following link:

Unpack the files into your JobScheduler's live folder and run the order using JOC.

The example behavior described above will be visible in the order log file.

Further References

Job and Order Parameters