Versions Compared

Key

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

...

Code Block
languagepy
titleExample for use of Environment Variables in a Python job script
linenumberstrue
#!/usr/bin/python

import os

print('using workflow: ', os.environ.get('JS7_WORKFLOW_NAME'))
print('running job: ', os.environ.get('JS7_JOB_NAME'))

print('Business Date: ', os.environ.get('BUSINESS_DATE'))
print('Flight Number: ', os.environ.get('FLIGHT_NUMBER'))
Code Block
languagejs
titleExample how run for use of Environment Variables in a Node.js® script code with a shebangjs job script
linenumberstrue
#!/usr/bin/node

console.log('using workflow: ' + process.env.JS7_WORKFLOW_NAME);
console.log('running job: ' + process.env.JS7_JOB_NAME);

console.log('Business Date: ' + process.env.BUSINESS_DATE);
console.log('Flight Number: ' + process.env.FLIGHT_NUMBER);

Passing Variables

Jobs can pass variables to subsequent jobs and JS7 - Workflow Instructions like this:

  • The JS7 Agent offers an environment variable JS7_RETURN_VALUES that holds the path to a temporary file.
  • Jobs can append key/value pairs to the temporary file.
  • On completion of the job the JS7 Agent will read the temporary file and will make related workflow variables available for subsequent jobs.

Examples:

Code Block
languagebash
titleExample for passing variables from a Unix Shell job script
linenumberstrue
#!/bin/bash

SOME_VAR=$RANDOM
echo "my_var=$SOME_VAR" >> $JS7_RETURN_VALUES
Code Block
languagetext
titleExample for passing variables from a Windows Shell job script
linenumberstrue
set SOME_VAR=%RANDOM%
echo my_var=%SOME_VAR% >> %JS7_RETURN_VALUES%
Code Block
languagebash
titleExample for passing variables from a PowerShell job script
linenumberstrue
#!/usr/bin/env pwsh

$someVar = Get-Random
"my_var=$someVar" | Out-File $env:JS7_RETURN_VALUES -Append
Code Block
languagebash
titleExample for passing variables from a Python Shell job script
linenumberstrue
#!/usr/bin/python
 
import random;

someVar = random.randint(0,9)
with open(os.environ.get('JS7_RETURN_VALUES'), 'a') as f:
    print(f"my_var={someVar}", file=f)
Code Block
languagejs
titleExample for passing variables from a Node.js job script
linenumberstrue
#!/usr/bin/node

const fs = require('fs');

var someVar = Math.random();
fs.appendFile(process.env.JS7_RETURN_VALUES, 'my_var=' + someVar + '\n', (err) => {});

Further Resources

How To

...