Passing parameters from one action to another in Oozie

8.2k views Asked by At

I have a following shell script:

DATE= date +"%d%b%y" -d "-1 days"

How can I pass DATE to a Java action?

1

There are 1 answers

2
InfamousCoconut On

You can capture output from shell script and pass it to java action.In the shell script , echo the property like 'dateVariable=${DATE}' and add the capture-output element int the shell action. This will let you capture dateVariable from shell script.In the java action, You can pass the captured variable as parameter as ${wf:actionData('shellAction')['dateVariable']} where shellAction is the shell action name.

Sample workflow :-

<?xml version="1.0" encoding="UTF-8"?>
<workflow-app xmlns="uri:oozie:workflow:0.4"
    name="Test workflow">
    <start to="shellAction" />
    <action name="shellAction">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>test_script.sh</exec> <file>${nameNode}/${workFlowLocation}/Scripts/test_script.sh#test_script.sh</file>          
            <capture-output />
        </shell>
        <ok to="JavaAction" />
        <error to="fail" />
    </action>

    <action name="JavaAction">
        <java>
            <main-class>com.test.TestDriver</main-class>
            <arg>${wf:actionData('shellAction')['dateVariable']}</arg>
            <capture-output />
        </java>
        <ok to="end" />
        <error to="fail" />
    </action>

    <kill name="fail">
        <message>Job failed, error
            message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end" />
</workflow-app>

In the shell script ,echo the value as below

 echo "dateVariable=${dateValue}"