Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Accessing parameters in shell scripts
- Job and order parameters 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 SCHEDULER_PARAM_ .
- Environment variable names are provided with uppercase letters.
- For example, a parameter param1 can be accessed by the SCHEDULER_PARAM_PARAM1 environment variable.
For details see Which environment variables are provided by JobScheduler?
Examples
The following two examples show a task parameter defined in a job <param> tag can be called in a shell script.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<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 | ||||||
---|---|---|---|---|---|---|
| ||||||
<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 "Parameter param1 has the value $SCHEDULER_PARAM_PARAM1" ]]> </script> <run_time/> </job |
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.
- JobScheduler parses a temporary file for name/value pairs after termination of each job in a job chain.
- The name of this temporary file is held in the 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%
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<job_chain> <job_chain_node state="100" job="job1_shell_with_parameter_set" next_state="200" error_state="error"/> <job_chain_node state="200" job="job2_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.
...
- 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:
...
The example behavior described above will be visible in the order log file.
Further References
Job and Order Parameters
- How to set and read job and order parameters
- How to access order parameters and job parameters using the JobScheduler API
- How to dynamically use node parameters and internal parameter substitutionHow to clone parameters from a persistent order
Environment Variables