Introduction
- The JS7 offers to perform any operation on orders, workflows, jobs and related objects by the JS7 - REST Web Service API.
- Note that any operation available with the JOC Cockpit GUI makes use of the REST Web Service API.
- For detailed information see the Technical Documentation of the REST Web Service API.
- The REST Web Service API can be accessed from Shell utilities such as
curl
. - In addition, a PowerShell module is available for simplified access to the REST Web Service API. This is described in the JS7 - PowerShell Module article.
The Job Resource Update Script introduced in this article can be used to update variables in JS7 - Job Resources.
The script can be considered an alternative for use of the respective JS7 PowerShell cmdlets, see JS7 - How to make a global Business Date variable available to jobs.
Job Resource Update Script
The Job Resource Update Script is provided for download and can be used to automate updates of job resources.
- The script is available for Linux and MacOS® using bash, dash, ksh and zsh POSIX-compatible shells.
- The script terminates with exit code 0 to signal success, with exit code 1 for command line argument errors and with exit code 4 for non-recoverable errors.
- The script is intended as a baseline example for customization by JS7 users and by SOS within the scope of professional services.
Prerequisites
The Job Resource Update Script requires the jq utility to be available from the operating system.
jq is ships with the MIT license, see https://opensource.org/licenses/MIT.
Download
Download: set_job_resource.sh
Usage
Invoking the script without arguments displays the usage clause:
Usage: set_job_resource.sh [Options] [Switches] Options: --url=<url> | required: JOC Cockpit URL --controller-id=<identifier> | required: Controller ID --job-resource=<path> | required: path to job resource --key=<identifier> | required: name of argument in job resource --value=<string> | required: value of argument in job resource --env-var=<identifier> | optional: name of environment variable in job resource --user=<account>[:<password>] | optional: user account for login to JOC Cockpit, use <account> or <account>:<password> --cacert=<path> | optional: path to Root CA Certificate for HTTPS connections --client-cert=<path> | optional: path to Client Certificate for HTTPS mutual authentication --client-key=<path> | optional: path to Client Private Key for HTTPS mutual authentication --log-dir=<directory> | optional: log directory for log output of this script Switches: -h | --help | displays usage -v | --verbose | shows verbose log output --show-logs | shows log output if --log-dir is used --make-dirs | creates directories if they do not exist
Options
--url
- Specifies the URL by which JOC Cockpit is accessible using
<http|https>://<host>:<port>
. - Example: http://centostest-primary.sos:4446
- Example: https://centostest-primary.sos:4443
- Specifies the URL by which JOC Cockpit is accessible using
--controller-id
- Specifies the Controller ID to which the updated job resource should be deployed.
--job-resource
- Specifies the path to the job resource in the JOC Cockpit inventory.
--key
- Specifies the name of an argument in the job resource specified with the
--job-resource
option. - Job Resource arguments are case-sensitive.
- Specifies the name of an argument in the job resource specified with the
--value
- Specifies the value of the argument in the job resource specified with the
--job-resource
option.
- Specifies the value of the argument in the job resource specified with the
--env-var
- Optionally specifies the name of an environment variable in the job resource specified with the
--job-resource
option. - The environment variable will be assigned a reference to the argument specified by the
--key
option to hold the same value as the argument. - Job Resource environment variables are case-sensitive.
- Optionally specifies the name of an environment variable in the job resource specified with the
--user
- Specifies the user account for login to JOC Cockpit. Specification of the user account can be omitted if a JS7 - Identity Services is available for Client authentication certificates that are specified with the
--client-cert
and--client-key
options. --user=<account>
can be specified to cause the password to be prompted.--user=<account>:<password>
can be specified.
- Specifies the user account for login to JOC Cockpit. Specification of the user account can be omitted if a JS7 - Identity Services is available for Client authentication certificates that are specified with the
--cacert
- Specifies the path to a .pem file that holds the Root CA Certificate and optionally Intermediate CA Certificates to verify HTTPS connections to JOC Cockpit.
--client-cert
- Specifies the path to a .pem file that holds the Client Certificate if HTTPS mutual authentication is used..
--client-key
- Specifies the path to a .pem file that holds the Client Privae Key if HTTPS mutual authentication is used..
--log-dir
- If a log directory is specified then the script will log information about processing steps to a log file in this directory.
- File names are created according to the pattern:
set_job_resource.<yyyy>-<MM>-<dd>T<hh>-<mm>-<ss>.log
- For example:
set_job_resource.2022-03-19T20-50-45.log
Switches
-h | --help
- Displays usage.
-v | --verbose
- Displays verbose log output.
--show-logs
- Displays the log output created by the script if the
--log-dir
option is used.
- Displays the log output created by the script if the
--make-dirs
- If directories are missing that are indicated with the
--home
,--backup-dir
or--log-dir
options then they will be created.
- If directories are missing that are indicated with the
Exit Codes
1
: argument errors4
: this exit code is returned if the JS7 REST Web Service is not reachable or reports errors
Examples
The following examples illustrate typical use cases.
Update Job Resource from HTTP Connection
./set_job_resource.sh \ --url=http://joc-2-0-primary:7446 \ --controller-id=controller \ --user=root:root \ --job-resource=/ProductDemo/Variables/pdBusinessDate \ --key=businessDate \ --value=$(date +'%Y-%m-%d') # updates the job resource argument "businessDate" from the current date # the connection to JOC Cockpit is established by HTTP
Update Job Resource from HTTPS Connection
./set_job_resource.sh \ --url=https://joc-2-0-primary:7446 \ --cacert=/home/sos/jstest/certs/root-ca.pem \ --controller-id=controller \ --user=root:root \ --job-resource=/ProductDemo/Variables/pdBusinessDate \ --key=businessDate \ --env-var=BUSINESS_DATE \ --value=$(TZ=Europe/London date +'%Y-%m-%d') # updates the job resource argument "businessDate" from the current date # the environment variable "BUSINESS_DATE" will be assigned the same date from a reference to the argument # the date is specified from the UK time zone # the connection to JOC Cockpit is established by HTTPS and the Root CA Certificate is specified from the path to a .pem file