Introduction
- Shell Jobs can be used for a number of scripting languages such as Bash, Perl, PowerShell etc.
- Users frequently re-use code snippets across a number of jobs, for example re-usable functions that are called in a number of jobs scripts.
- This applies to Shell Jobs using Bash etc. and it applies to the use of any scripting languages.
- Code snippets can be managed by the use of Script Includes that are available as inventory items in the Configuration view of JOC Cockpit.
- FEATURE AVAILABILITY STARTING FROM RELEASE 2.2.0
- - JOC-1170Getting issue details... STATUS
Managing Script Includes
Script Includes are managed from the Configuration view for a number of use cases.
Use Case: Global Functions
This use case includes defining functions, e.g. for bash scripts, that can be used across job scripts in a number of workflows:
Use Case: Environment Variables
Script Includes can be used to define environment variables that are used in a number of shell scripts:
Hint:
- Use of JS7 - Job Resources is preferable if the only purpose of the Script Include is to publish environment variables to shell scripts.
Use Case: Shebang Replacement
Script Includes can be used as a shebang replacement:
Hint:
- The somewhat cryptic line in fact allows the addition of multi-line PowerShell code to job scripts for Windows, see JS7 - How to run PowerShell scripts from jobs.
Applying Script Includes
Use Case: Global Functions
Script Includes can be applied to any Shell Jobs. Consider the example of a workflow that includes a Shell Job such as:
The job script in the above workflow looks like this:
Use Case: Shebang Replacement
The above example of a Script Include that hides the complexity of a shebang replacement for PowerShell with Windows is applied like this:
Adding Script Includes to a Job Script
Script Includes can be added to a job script in a number of ways:
- Users can type
##!include
at the begin of a line in the job script followed by the name of the Script Include. - When hitting
Ctrl+Space
directly after typing##!include
then a popup window will offer the list of available Script Includes for selection. - The first line of the script editor popup window offers the icon. Clicking this icon displays the list of folders from which a Script Include is chosen and added to the cursor position:
Syntax
Script Includes can be added to a job script using the following syntax:
(##|::|//)!include script-include-name [--replace="search literal","replacement literal" [--replace=...]]
Explanation:
- The first two characters in a line of the job script are:
##
or::
or//
- followed by:
!include
- followed by the name of the Script Include
- optionally followed by repeated occurrences of:
--replace="...", "..."
- the
--replace
option accepts- as its first argument a literal string to be searched for in the Script Include,
- as its second argument the literal replacement for the search literal.
- This option can be included any number of times.
- the
- Any number of Script Includes can be embedded in a job script.
Examples
The following examples show how to apply Script Includes:
##!include pdScriptBashFunctions ##!include pdScriptBashEnvironmentVariables --replace="/tmp/js7","/home/js7" --replace="/var/myapp","/home/js7/myapp"
Handling of Script Includes
Deployment
- Script Includes are embedded at the point in time of deployment of a workflow.
- Script Includes have to be released in order to be considered for deployment with a workflow.
Change Management
- If the contents of a Script Include is modified after deployment of a workflow then this change does not affect the deployed workflow.
- If a Script Include does not exist any longer at the point in time of deployment of a workflow then an error is raised.
- If the name of a Script Include is modified then this is reflected with jobs in any workflows that make use of the Script Include. A draft which includes the modified reference to the Script Include is created for any affected workflows.