...
Code Block |
---|
# Example Shell: echo name1 = value2 >> %SCHEDULER_RETURN_VALUES% # Example PowerShell solution 1: $spooler_task.order().params().set_value( "name1", "value2" ) # Example PowerShell solution 2: shorthand notation for task/order parameter $spooler_params.set( "name1", "value2" ) |
Profile Handling
Profile Locations
JobScheduler handles PowerShell profiles in a similar way to the PowerShell host.
- The $PROFILE variable returns a collection of locations that a profile is looked up for. By default PowerShell would use four variables as stated below that are mapped by JobScheduler to two possible profile locations.
- If a profile is found in a number of locations then all profiles are processed in the sequence as stated below.
Profile locations (<agent_data>
points to the data directory that is configured for an Agent, usually by use of the SCHEDULER_DATA environment variable with the Agent instance script):
- $PROFILE.AllUsersAllHosts, $PROFILE.AllUsersCurrentHost
<agent_data>\config\powershell\JobScheduler.PowerShell_profile.ps1
- $PROFILE.CurrentUserAllHosts, $PROFILE.CurrentUserCurrentHost
- Agent/Job runs as system account: the same profile as stated above is processed
<agent_data>\config\powershell\JobScheduler.PowerShell_profile.ps1
- Agent/Job runs as user account: the profile is looked up in the
Users
sub-directory for the current user (indicated by<user_name>
).<agent_data>\config\Users\<user_name>\powershell\JobScheduler.PowerShell_profile.ps1
- Agent/Job runs as system account: the same profile as stated above is processed
For details check
Jira | ||||||||
---|---|---|---|---|---|---|---|---|
|
Use of Profiles
Profiles can be used
- to specify alias names for cmdlets,
- to specify global variables, e.g. paths, that can be used by all jobs,
- to import PowerShell modules, e.g. to specify
Import-Module JobScheduler
for use of the PowerShell CLI - to specify the behavior in case of errors by use of the
$ErrorActionPreference variable
- A value
$ErrorActionPreference = "Continue"
(Default) allows a PowerShell script to continue after an error occurred. It is up to the script developer to check for errors, e.g. by use of exceptions. - A value
$ErrorActionPreference = "Stop"
is the recommended setting as it immediately stops execution of the script after an error occurred
- A value
Error Handling
PowerShell jobs offer a number of options to detect run-time errors.
...
- If a native Windows program or script (.bat, .cmd) causes an error then this will assign the exit code to the
$LastExitCode
global variable.- The same is true for ne
- This behavior does not apply to cmdlets causing errors.
- JobScheduler checks this variable and will set the job exit code accordingly. For exit codes != 0 an error is raised.
- This behavior is superior compared to shell jobs as errors from any line in the job script are detected. For shell scripts only the last line of a job script determines the execution result (Unix:
$?
, Windows:%ERRORLEVEL%
).
...