You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

Scope

  • JobScheduler offers Powershell as a language for implementation of Jobs
  • Powershell Jobs have to been seen as the analogy for the Shell Jobs, even though there are some differences between Shell and Powershell Jobs
  • The decision to include Powershell as a language for JobScheduler (among others) is in the same line with the development of Microsoft programming languages
  • Powershell Jobs can only be run on Agents and not on the Master

Feature Availability

FEATURE AVAILABILITY STARTING FROM RELEASE 1.10.5

Powershell as a Shell

As mentioned before, Powershell Jobs should be seen as the analogy for Shell Jobs in the future. That means, every Shell job should be able to be (with any or few changes) converted into a Powershell job. 

Nevertheless, there are some compatibility issues described below.

Calling Order parameters or Job parameters

Example Shell: 
myscript.cmd %SCHEDULER_PARAM_NAME1%

Example Powershell: 
myscript.cmd $env:SCHEDULER_PARAM_NAME1

Returning a parameter an its value to an Order

Example Shell: 
echo NAME1 = VALUE1 >> %SCHEDULER_RETURN_VALUES%

Example Powershell: 
echo "NAME1 = VALUE1" >> $env:SCHEDULER_RETURN_VALUES%

Exit Code Handling

The following example throws no error in Shell but it breaks at line 2 and ends in an error for Powershell:

echo job is starting
abcde
echo job is finishing

The same example would be working in Powershell the following way:

echo job is starting
try{abcde}
catch{}
echo job is finishing

This type of differences described above will be furhter supported like this from JobScheduler and seen as natural differences between the Shell and Powershell languages.

Examples

Example: Powershell as a Shell

A simple job with some scripting analogue to basic Shell jobs might look like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<job  process_class="/tests/Agent">
    <script  language="powershell">
echo "job is starting"
sleep 10
$files = dir *
echo $files
echo job is finishing
    </script>
    <run_time />
</job>

 

Example: Powershell API Jobs

tbd

 <job process_class="my_process_class">
 <script language="powershell">
 <![CDATA[
Import-Module JobScheduler
use-master myjobscheduler:4444
get-status

 ]]>
 </script>
<run_time />

Example: Combination of both (Job with Monitors) 

tbd

<?xml version="1.0" encoding="ISO-8859-1"?>

<job  process_class="/tests/Agent">
    <script  language="powershell">


echo job is starting
sleep 10
echo job is finishing

    </script>
    <monitor  name="process_powershell" ordering="0">
        <script  language="powershell">
            <![CDATA[
		function spooler_process_before()
		{
		$env:files = get-childitem *
		echo $files
		$spooler_log.info("hallo")
		return $false
		}
            ]]>
        </script>
    </monitor>
    <run_time />
</job>

Example: PowerShell Job with Debug output

 

<?xml version="1.0" encoding="ISO-8859-1"?>


<job  process_class="Agent01" stop_on_error="no">
    <settings >
        <log_level ><![CDATA[debug1]]></log_level>
    </settings>

    <script  language="powershell">
        <![CDATA[
# Standard PowerShell verbose setting is considered for jobs:
$VerbosePreference = "continue"
Write-Verbose "job: this is some verbose output"

# Standard PowerShell debug setting is ignored for jobs:
#   $DebugPreference = "continue"
# Instead the current log level of the job is applied, e.g. log level "debug1" logs debug messages
Write-Debug "job: this is some debug output"

Write-Warning "job: this is a warning"

# This can be used to throw an error
# Write-Error "job: this is an error"

# This does not work: Use of Write-Host is not allowed
# Write-Host "job: this is some output"
        ]]>
    </script>

    <run_time />
</job>

 

Extras: CLI for Powershell Jobs

 <job process_class="my_process_class">
 <script language="powershell">
 <![CDATA[
Import-Module JobScheduler
use-master myjobscheduler:4444
get-status

 ]]>
 </script>
<run_time />

 

 

 

  • No labels