REST call to uploaded script results in "Missing engine for language: string"


#1

Hi,
I have two scripts uploaded, which list as
[ {
“name” : “test”,
“content” : “println(‘Hello test’)”,
“type” : “string”
}, {
“name” : “helloarg”,
“content” : “String.valueOf(args)”,
“type” : “string”
} ]
Whichever I run from the API page or the commandline, I get a Json result : “Missing enging for language: string”:

$ curl -X POST -u admin:admin123 --header “Content-Type: text/plain” “http://localhost:8081/service/rest/v1/script/helloarg/run” -d “Hello”
< HTTP/1.1 400 Bad Request
{
“name” : “helloarg”,
“result” : “Missing engine for language: string”
}

$ curl -X POST -u admin:admin123 --header “Content-Type: text/plain” “http://localhost:8081/service/rest/v1/script/test/run
{
“name” : “test”,
“result” : “Missing engine for language: string”
}

In the logViewer I see that this is a java.lang.IllegalStateException.
In any case, it is not caused by the Json type argument “string”, because “String” results in the same.
Eventually I need to pass an argument with value of a specific GAV from Jenkins, after having released successfully, to run the Nexus script on this GAV.


#2

You need to set the content-type header to “application/json”:

--header "Content-Type: application/json"

Rich


#3

@Alx

This is what I can make out if it!

Below is my script:

import groovy.json.JsonOutput
import groovy.json.JsonSlurper

def input = new JsonSlurper().parseText(args)
def output = [:]

log.info("***********************************************")
log.info("Running the script Test")
log.info("***********************************************")

output.put("status", "200 OK")
output.put("g", input.g)
output.put("a", input.g)
output.put("v", input.v)

return JsonOutput.toJson(output)

Then I create the JSON file as:

{
  “name” : “test”,
  “type” : “groovy”
  “content” : “I read the above script file here / you can also copy paste it here”,
}

Then while running the script you can pass a json style string to the script. The script will be able to parse it!

Req: https://localhost:8443/service/rest/v1/script/test/run
payload: {“g”: “com.company”,“a”: “artifact”,“v”: “1.0.0”}
Header : Basic Auth and Content-Type: text/plain
Resp:

{
“name”: “test”,
“result”: “{“status”:“200 OK”,“g”:“com.company”,“a”:“com.company”,“v”:“1.0.0”}”
}

The script just formats and return the same to me. I can then also parse this info.

Since a week I am writing these function into a Golang CLI, check it out if it helps you: GitHub - atselvan/nexus3-repository-cli: Nexus 3 CLI


#4

Thank you, I will definitely give it a try!
Allthough it looks like a Mime-type problem, the system/API page does not seem to work consistently with application/json.

This still works with a “onelined” script, but if it works it works!
The Sonatype complex-script example shows it can also be done with a REST call.


#5

Indeed, I even get result without the Mime-type:

curl -X POST -u admin:admin123 “http://localhost:8081/service/rest/v1/script/test/run” “{“g”: “com.company”,“a”: “artifact”,“v”: “1.0.0”}”

Thanks !


#6

Rich, thanks for the reply, but If I upload this script through the API page via add
{
“name”: “hello”,
“content”: “log.info(“Hello”)”,
“type”: “string”
}
and call it through the run option I get the HTTP 400 / Bad Request: “Missing engine for language: string” result.
I can not choose alternative Mime-types for either action.

Running the script by cUrl the Mime-type does not matter for the exception in the logViewer.

However, the solution offered by atselvan works.