...
Code Block |
---|
language | py |
---|
title | Example for use of Environment Variables in a Python job script |
---|
linenumbers | true |
---|
|
#!/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 |
---|
language | js |
---|
title | Example how run for use of Environment Variables in a Node.js® script code with a shebangjs job script |
---|
linenumbers | true |
---|
|
#!/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 |
---|
language | bash |
---|
title | Example for passing variables from a Unix Shell job script |
---|
linenumbers | true |
---|
|
#!/bin/bash
SOME_VAR=$RANDOM
echo "my_var=$SOME_VAR" >> $JS7_RETURN_VALUES |
Code Block |
---|
language | text |
---|
title | Example for passing variables from a Windows Shell job script |
---|
linenumbers | true |
---|
|
set SOME_VAR=%RANDOM%
echo my_var=%SOME_VAR% >> %JS7_RETURN_VALUES% |
Code Block |
---|
language | bash |
---|
title | Example for passing variables from a PowerShell job script |
---|
linenumbers | true |
---|
|
#!/usr/bin/env pwsh
$someVar = Get-Random
"my_var=$someVar" | Out-File $env:JS7_RETURN_VALUES -Append |
Code Block |
---|
language | bash |
---|
title | Example for passing variables from a Python Shell job script |
---|
linenumbers | true |
---|
|
#!/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 |
---|
language | js |
---|
title | Example for passing variables from a Node.js job script |
---|
linenumbers | true |
---|
|
#!/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
...