Versions Compared

Key

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

...

  • Users frequently find the situation that jobs in a workflow pass variables to subsequent jobs.
  • This can easily be achieved by appending a pair of namea name/value pair for the variable to a temporary file that is offered by the JS7_RETURN_VALUES environment variable like this:

    Code Block
    languagebash
    titleExample how to pass a variable to subsequent jobs with Unix
    MY_VAR="some text"
    echo "my_variable=$MY_VAR" >> $JS7_RETURN_VALUES
    Code Block
    languagebash
    titleExample how to pass a variable to subsequent jobs with Windows
    set MY_VAR=some text
    echo my_variable=%MY_VAR% >> %JS7_RETURN_VALUES%


    Explanation:

    • A variable The my_variable variable is passed as an order variable to subsequent jobs and instructions in a workflow.
    • The This variable can be assigned a constant value or a value from some an arbitrary environment variable such as e.g. MY_VAR that which holds some an arbitrary value.
  • However, there are two limitations about this approach:
    • The length of values for environment variables is limited , - the precise max. size of environment variables is OS dependent.
    • If the value of the variable includes special characters such as carriage return, newline , or linefeed then this might break depending on capabilities of environment variables in the OS.

...

  • To address the problem of special characters, use base64 encoding for variable values as this encoding results in a single printable string.
  • To address the limitation concerning the size of environment variables do not use them and instead think about ways how to directly append lines to the temporary file indicated by JS7_RETURN_VALUES
  • Display feature availability
    StartingFromRelease2.2.0

Example

  • Let's assume two jobs are to be executed in sequence:
    • The the first job creates a lengthy e-email body in HTML format ,and
    • The the second job sends an e-mail and makes use of using the HTML body. Find
  • There are a number of possible implementations for the JS7 job script:


    Code Block
    languagebash
    titleExample for Shell version using environment variables on Unix
    #!/user/bin/env bash
    
    mailBody="<html><body><b>hello</b> <i>world</i></body></html>"
    mailBodyEncoded=$(echo $mailBody | base64)
    echo "body=base64:$mailBodyEncoded" >> $JS7_RETURN_VALUES
    Code Block
    languagebash
    titleExample for Shell version using files on Unix
    #!/user/bin/env bash
    
    echo "<html><body><b>hello</b> <i>world</i></body></html>" > /tmp/mail-body.html
    echo "body=base64:$(cat /tmp/mail-body.html | base64)" >> $JS7_RETURN_VALUES
    Code Block
    languagebash
    titleExample for PowerShell version on Unix
    #!/usr/bin/env pwsh
    
    $mailBody = "<html><body><b>hello</b> <i>world</i></body></html>"
    $mailBodyEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( $mailBody ))
    "body=base64:$mailBodyEncoded" | Out-File $env:JS7_RETURN_VALUES -Append
    Code Block
    titleExample for PowerShell version on Windows (multi-line)
    @@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof
    
    $mailBody = "<html><body><b>hello</b> <i>world</i></body></html>"
    $mailBodyEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( $mailBody ))
    "body=base64:$mailBodyEncoded" | Out-File $env:JS7_RETURN_VALUES -Append
    Code Block
    titleExample for PowerShell version on Windows (single-line)
    pwsh.exe -NoLogo -NonInteractive -Command "& { ""body=base64:$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( '<html><body><b>hello</b> <i>world</i></body></html>' )) )"" | Out-File $env:JS7_RETURN_VALUES -Append }"


    Explanation:
    • In fact the e-mail body is not too lengthy

      , however

      . However, it suggests that an e-mail body of arbitrary size would be imported by

      some

      a template file as

      e.g. for PowerShell

      , for example, in the case of PowerShell, with $mailBody = Get-Content "mail-body.html"

      • The above bash version with files and the PowerShell version both work with arbitrary length values.
    • Base64 encoding is available from a number of sources such as the base64 Unix utility or the .NET Core class.
    • The value of the body variable is prefixed with base64: to indicate the encoding.
    • The subsequent JS7 - JITL MailJob accepts the body variable, identifies the encoding and automatically decodes the argument value.