2

I would like to execute a XQuery script directly from Gradle instead of from QConsole. How to do that?

Is there a mlGradle task for that? Or we could define a task like running MLCP from gradle?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147

1 Answers1

3

You can create a custom task that extends the ServerEvalTask.

As demonstrated in the Custom tasks that talk to the Client REST API WIKI page

task myXQueryTask(type: com.marklogic.gradle.task.ServerEvalTask) {
  xquery = "my XQuery code here"
}

If you are looking to read the contents of the code from a particular file, instead of a static string, then could instead do something like:

new File('/path/to/file').getText('UTF-8')
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • great thanks. It is what I am after ; ) 1) Is it common (or ML recommended way) to use gradle to run Xquery code? 2) **Corb2** is for data update and data reporting. I wonder Corb2 could be used for simple admin task like start ml db backup. 3) With Gradle or Corb2, it is possible to implement **CI/CD** as they both could run in _terminal_. Any other tools for ML **CI/CD**? Again, great thanks. – XCELERENT - I want to dance Aug 14 '21 at 20:49
  • CoRB also has a ModuleExecutor class that can be configured the same way as a CoRB job https://github.com/marklogic-community/corb2/wiki/ModuleExecutor-Tool. Whether you execute from shell scripts or gradle tasks to invoke CoRB classes or the ServerEvalTask, or something else to execute modules for CI/CD is your choice. Either would work fine. – Mads Hansen Aug 14 '21 at 20:57