Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • A Job Resource can hold any number of variables. Such variables are available for JVM Jobs from arguments and for Shell Jobs from environment variables.
  • A Job Resource environment variable is automatically available as a local environment variable to a Shell Job.
    • If a Workflow is assigned the Job Resource then any Shell Jobs in the workflow are propagated the environment variables of the Job Resource.
    • If a Job is assigned the Job Resource then this job can use the propagated environment variables of the Job Resource.
  • As a result you can add a variable such as BusinessDate to an existing or to a new Job Resource and assign the Job Resource to a Workflow to make it available to all jobs or assign it to an individual Job to limit the scope.

Download: pdBusinessDate.jobresource.json

The Job Resource can be configured with the "Arguments" tab like this:

  • an argument with the name businessDate is introduced that holds an arbitrary date value.

Image Added


For the same Job Resource switch to the tab "Environment Variables" to complete the configuration like this:

  • An environment variable with the name BUSINESS_DATE is using the value of the $businessDate argument.
  • The environment variable is available for any jobs that are assigned this Job Resource

Image Added

Then deploy the above Job Resource.

Use with Jobs

Environment variables from Job Resources are automatically available for job scripts.

  • For jobs executed with Unix Agents the environment variable is available from its name, e.g. $BUSINESS_DATE.
  • For jobs executed with Windows Agents the environment variable is available from the syntax %BUSINESS_DATE%.

Job for Unix

Download for Unix: pduVariableBusinessDateGet.workflow.json

The job is assigned the Job Resource with the given name. In the job script the environment variable $BUSINESS_DATE is used that is available from the Job Resource.

Image Added

Job for Windows

Download for Windows: pdwVariableBusinessDateGet.workflow.json

The job is assigned the Job Resource with the given name. In the job script the environment variable %BUSINESS_DATE% is used that is available from the Job Resource.

Image Added

Updating the Business Date

...

Code Block
languagepowershell
titlePowerShell implementation to update the business date with a Job Resource variable
linenumberstrue
#!/usr/bin/env pwsh

# ---- environment specific -----
# Consider to use the appropriate URL that matches host and port of the JOC Cockpit instance
$url = "http://localhost:4446"

# Consider to store credentials with a PowerShell profile or with a credential store or to use certificate based authentication as an alternative to user/password
$credential = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList 'root', ( 'root' | ConvertTo-SecureString -AsPlainText -Force) )

# Consider the identification of the Controller that the job resource should be deployed to
$controllerId = "testsuite"
# ---- environment specific -----


Import-Module JS7
Connect-JS7 -Url $url -Credential $credential -Id $controllerId

$jobResource = Get-JS7InventoryItem -Path /Defaults/DailyDefault -Type JOBRESOURCE

    if ( $jobResource.arguments.BusinessDate )
    {
        # update the business date
        $jobResource.arguments.BusinessDate = (Get-Date -Format "yyyy-MM-dd")
    } else {
        # add a business date variable to the Job Resource
        $jobResource.arguments | Add-Member -Membertype NoteProperty -Name BusinessDate -Value (Get-Date -Format "yyyy-MM-dd")
    }

# Update and deploy the Job Resource
Set-JS7InventoryItem -Path /Defaults/DailyDefault -Type JOBRESOURCE -Object $jobResource
Publish-JS7DeployableItem -Path /Defaults/DailyDefault -Type JOBRESOURCE -ControllerID $controllerId
DisconectDisconnect-JS7


For Windows use the above PowerShell script code except for the first line (that indicates a shebang) that should be replaced by:

...