Support Questions

Find answers, ask questions, and share your expertise

Create a global variable in Oozie to be accessible to all actions?

avatar
Explorer

I want to create a variable that should be available to all the actions in the Oozie workflow. I have tried to create it as shown below. But EL expression is not getting evaluated resulting in variable current_ts value as EL expression itself. Can somebody please throw some light on this?

    <workflow-app xmlns="uri:oozie:workflow:0.4" name="no-op-wf">
      <parameters>
        <property>
          <name>current_ts</name>
          <value>${replaceAll((replaceAll((replaceAll((timestamp()),"-","")),"T","_")),":","")}</value>
        </property>
      </parameters>
      <start to="test"/>
      <kill name="test">
        <!--message Just to show that this expression works if used here>Timestamp - [${replaceAll((replaceAll((replaceAll((timestamp()),"-","")),"T","_")),":","")}</message-->
        <message>Timestamp - ${current_ts}</message> <!-- this will print expression but not evaluate it -->
      </kill>
      <end name="end"/>
    </workflow-app>

1 ACCEPTED SOLUTION

avatar
Super Collaborator

@Abb Code Just try to see if by defining the required variable through global section in workflow.xml helps you. More details about defining global is available at following URL.

https://oozie.apache.org/docs/4.2.0/WorkflowFunctionalSpec.html#a19_Global_Configurations

View solution in original post

2 REPLIES 2

avatar
Super Collaborator

@Abb Code Just try to see if by defining the required variable through global section in workflow.xml helps you. More details about defining global is available at following URL.

https://oozie.apache.org/docs/4.2.0/WorkflowFunctionalSpec.html#a19_Global_Configurations

avatar
Explorer

Thanks @peeyush . I was able to use global property section to create a global variable and reference it in different actions in workflow. But it didn't work in the same workflow, I had to pass it to a sub workflow as a configuration property from another workflow.

  <global>
    <configuration>
      <property>
        <name>run_ts</name>
        <value>${replaceAll((replaceAll((replaceAll((timestamp()),"-","")),"T","_")),":","")}</value>
      </property>
    </configuration>
  </global>


 <action name="coaching-tbl-subwf">
    <sub-workflow>
      <app-path>/data/app/subwf.xml</app-path>
      <propagate-configuration/>
 </configuration>
    </sub-workflow>
    <ok to="join-node"/>
    <error to="fail"/>
  </action>