Passing data to child job as workflow step

16 views
Skip to first unread message

Mazz

unread,
Aug 28, 2025, 3:17:16 AM (11 days ago) Aug 28
to rundeck-discuss
Hi,

I have a job running on x nodes with some options. I capture some data I need to a child job which consists to send a mail saying that machine A has been updated with version X and so on. 

This child job grabs options and global variables from parent jobto get correct values for the mail.

If I run the child job as a node step it's working but it will send one mail per machine. What I would like to do is running the child job as a workflow step to send a single mail saying that machine A/B/C have been updated with version X/Y/Z and so on...
But when running as a workflow step I have a substitution error which is logical without node context :

/tmp/75-1601764-RUNDECK-dispatch-script.tmp.sh: line 20: ${data.version_installe}: bad substitution

Is there a way to do what I want ?

Parent job :

- defaultTab: nodes
  description:
  executionEnabled: true
  group: test
  id: 8e0f3863-344c-425b-91b3-ea4f0301bbc3
  loglevel: INFO
  name: PARENT
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'tags: PBI_${option.ENV}${option.NODE}'
  nodesSelectedByDefault: true
  options:
  - name: CHANGEMENT
  - name: ENV
    values:
    - REC
    - PRD
    valuesListDelimiter: ','
  - enforced: true
    name: NODE
    values:
    - '10'
    - '13'
    - ALL
    valuesListDelimiter: ','
  - name: Version
  plugins:
    ExecutionLifecycle: {}
  scheduleEnabled: true
  sequence:
    commands:
    - exec: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Unblock-File
        -Path test.ps1
      plugins:
        LogFilter: []
    - exec: 'pwsh Test_Version.ps1 '
      plugins:
        LogFilter: []
    - configuration:
        export: nom_machine
        group: export
        value: ${data.nom_machine*}
      nodeStep: false
      type: export-var
    - configuration:
        export: version_installe
        group: export
        value: ${data.version_installe*}
      nodeStep: false
      type: export-var
    - jobref:
        args: -version_installe "${data.version_installe}" -nom_machine "${data.nom_machine}"
        group: test
        importOptions: true
        name: CHILD
        nodeStep: 'true'
        uuid: 721f1a1a-0e36-4b93-8b71-f5be5f807abd
    keepgoing: false
    pluginConfig:
      LogFilter:
      - config:
          invalidKeyPattern: \s|\$|\{|\}|\\
          logData: 'true'
          regex: ^(version_installe)\s*=\s*(.+)$
          replaceFilteredResult: 'false'
        type: key-value-data
      - config:
          invalidKeyPattern: \s|\$|\{|\}|\\
          logData: 'true'
          regex: ^(nom_machine)\s*=\s*(.+)$
          replaceFilteredResult: 'false'
        type: key-value-data
    strategy: node-first
  uuid: 8e0f3863-344c-425b-91b3-ea4f0301bbc3

Child job :

- defaultTab: nodes
  description: ''
  executionEnabled: true
  group: test
  id: 721f1a1a-0e36-4b93-8b71-f5be5f807abd
  loglevel: INFO
  name: CHILD
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'tags: rundeck'
  nodesSelectedByDefault: true
  options:
  - name: CHANGEMENT
  - enforced: true
    name: ENV
    values:
    - REC
    - PRD
    valuesListDelimiter: ','
  - enforced: true
    name: NODE
    values:
    - '10'
    - '11'
    - '12'
    - '13'
    - ALL
    valuesListDelimiter: ','
  - name: Version
  - name: nom_machine
    required: true
  - name: version_installe
    required: true
  plugins:
    ExecutionLifecycle: {}
  scheduleEnabled: true
  sequence:
    commands:
    - autoSecureInput: 'false'
      passSecureInput: 'false'
      script: |-
        ################
        ### Function ###
        ################

        function MAIL_FIN_INSTALL ()
        {
            # Variables avec expansion Rundeck
            mail_to="@node.PATH_mail_to@"
            mail_cc="@node.PATH_mail_cc@"
            mail_exp="@node.PATH_mail_exp@"
            version_install="@option.Version@"
            version_serveur="@option.version_installe@"
            changement="@option.CHANGEMENT@"
            machine="@option.nom_machine@"
            version_installe="@option.version_installe@"

            if [[ "@option.CHANGEMENT@" =~ [A-Z]{1}[0-9]{6}_[0-9]{6} ]]; then
                echo "========================================================"
                echo "ceci est un envoi de mail pour la mise à jour standard."
                echo "========================================================"
            else
                mail_to="@node.PATH_mail_test_to@"
                mail_cc="@node.PATH_mail_test_cc@"
                mail_exp="@node.PATH_mail_test_exp@"

                echo "========================================"
                echo "ceci est un envoi de mail pour du TEST."
                echo "========================================"
            fi

            if [[ "@option.ENV@" = "PRD" ]]; then
                environnement="production"
            else
                environnement="recette"
            fi

            echo "===================================================="
            echo "Nous sommes sur l'environnement de : [$environnement]"
            echo "===================================================="

            if [[ "@option.NODE@" = "ALL" ]]; then
                echo "==============================================================="
                echo " nous sommes en [$environnement], envoi du mail en cours"
                echo " le mail sera envoyé par [$mail_exp] à [$mail_to] et [$mail_cc]"
                echo "==============================================================="

                echo '<!DOCTYPE html>
        <html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
        <head>
        <title>blabla</title>
        </head>
        <body>
        <p>Bonjour,<br /><br />
        blabla'$environnement'</strong> est terminée sur la machine : '$machine'.<br /><br />
        La version est : '$version_installe' ('$version_install') <br /><br />
        </body>
        </html>' | EMAIL="$mail_exp"  mutt -e 'set content_type="text/html"'  "$mail_to" -c "$mail_cc"  -s "[PBI ON CLOUD][@option.ENV@][@option.CHANGEMENT@] Mise a jour Datagateway Powerbi"

                echo -e "\n ### MAIL INSTALL @option.ENV@ sent.### \n"

            else
                echo "======================================================================================="
                echo " nous sommes en TEST sur l'environnement : [$environnement], envoi du mail en cours"
                echo " le mail de TEST sera envoyé par [$mail_exp] à [$mail_to] et [$mail_cc]"
                echo "======================================================================================="

                echo '<!DOCTYPE html>
        <html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
        <head>
        <title>PBI Auto Deploy</title>
        </head>
        <body>
        <p>Bonjour,<br /><br />
        Ceci est un <span style="color: red"><strong>test</strong></span>.<br /><br />
        blabla'$environnement'</strong> est terminée sur la machine : '$machine'.<br /><br />
        La version est : '$version_installe' ('$version_install') <br /><br />
        N°'$changement'<br /><br />
        Service Intégration Technique et Applicative 1</p>
        </body>
        </html>' | EMAIL="$mail_exp"  mutt -e 'set content_type="text/html"'  "$mail_to" -c "$mail_cc"  -s "[PBI ON CLOUD][TEST][@option.ENV@][@option.CHANGEMENT@] bla"

                echo -e "\n ### MAIL INSTALL @option.ENV@ sent.### \n"
            fi

            echo "###########################"
            echo "### fin d'envoi de mail ###"
            echo "###########################"
        }


        ############
        ### Main ###
        ############

        MAIL_FIN_INSTALL
    keepgoing: false
    strategy: node-first
  uuid: 721f1a1a-0e36-4b93-8b71-f5be5f807abd

javed...@gmail.com

unread,
Aug 28, 2025, 3:56:03 AM (11 days ago) Aug 28
to rundeck...@googlegroups.com
Hello, 

Could you do something like this? 

Your job runner runs on each node and pipes output to a file.

Declare that file as a rundeck variable.

Job runner: 

- defaultTab: nodes
  description: "Collect variables from each node and pass to downstream job"
  executionEnabled: true
  group: demo
  id: collector-job
  loglevel: INFO
  name: Collect-Variables
  nodeFilterEditable: false
  scheduleEnabled: true
  sequence:
    keepgoing: false
    strategy: node-first
    commands:
      # Step 1: Node step - run on each node
      - script: |
          echo "machine=${node.name},installed=success,packages=x,y,z" >> /tmp/results-${node.name}.txt
      # Step 2: Dispatcher step - aggregate
      - script:
          interpreter: /bin/bash
          script: |
            cat /tmp/results-*.txt > /tmp/all_results.txt
            echo "RD_OPTION_RESULTS=$(cat /tmp/all_results.txt)"
        nodeStep: false
  uuid: collector-job

Then call your mailer job as a job reference step:

- jobref:
          name: Receive-Variables
          group: demo
          args:
            results: ${job.context.results}

--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/rundeck-discuss/38596101-da0a-4ca9-a081-e0e69ebe2298n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages