Start Job HTTP API parameters

Is it possible to start a Job via the HTTP API and pass arguments that can be used in the job?

The Start Job HTTP API endpoint (POST /api/http/projects/{project}/automation/jobs/{jobId}/start) has an "parameters" argument.
However when that argument is specified the endpoint always returns the following error:
Following parameters are not defined in the list of the Job parameters and can't be passed for running the Job: example

How can I define Job parameters to allow via the HTTP API?

0
6 comments

Hi Florian,

Sure, here's an example of the request body:

{
    "branch": {
      "branchName": "main"
    },
    "parameters": [{
        "name": "",
        "value": ""
    }]
}

Please feel free to use our HTTP API Playground in Space UI to prepare a request with all necessary parameters in a more handy way.

0

Hello,

Thank you for the reply.
I tried using the API Playground but without luck.
I tried starting this job

job("Test") {
    container(displayName = "Test", image = "node:lts") {
        env["TEST"] = Params("test")
        shellScript {
            content = """
                env | grep TEST
            """
        }
    }
}

using this request body

{
    "branch": {
        "branchName": "main"
    },
    "parameters": [{
        "name": "test",
        "value": "hello world"
    }]
}

but got the following error as response:

{
    "className": "LaunchResult.Error",
    "message": "Following parameters are not defined in the list of the Job parameters and can't be passed for running the Job: test"
}
0

Florian - hi,

Could you please confirm that you have this parameter with the name `test` set up for the same project where you use it in the automation job (https://www.jetbrains.com/help/space/secrets-and-parameters.html)?

Looking forward to hearing from you!

0

Hi,

the parameter is defined.
The job can be started using the REST API, when not specifying a value for "parameters" in the POST body.
That uses the parameter defined in the projects settings.
I would want to override the default parameter value by specifying it in the POST body if possible.
The "parameter" parameter is missing in the API reference: https://www.jetbrains.com/help/space/projects-a.html#start_job so I am not sure how to use that.

My goal is to specify arguments in the "Start job" API request and then use them in the job itself.

0

Hi,

I'm trying to do the same thing, but using the kotlin space API with the same result. I have defined the parameters in the project setting, but when I try to start the job using

val job = api.space().projects.automation.jobs.startJob(
project = ProjectIdentifier.Key(api.projectKey()),
jobId = automationJobId,
branch = Branch(branchName = "main"),
parameters = listOf(
JobParameter("parameter1", "value1"),
JobParameter("parameter2", "value2)
))

I get the same error than Florian:

Error launching deploy job: Following parameters are not defined in the list of the Job parameters and can't be passed for running the Job: parameter1,parameter2
The same code without the parameters parameter works.
 
How should I call the job for starting it using parameters?
 
0

Juanluisrp - hi,

We've enabled the related feature flag for your organization. Now, in order to use parameter1 and parameter2, you need to add this section to the job dsl:

parameters {
    text("parameter1")
    text("parameter2")
}

For more information please refer to https://youtrack.jetbrains.com/issue/SPACE-13318 to figure out how to use params for a job.

Please let us know if further assistance is needed.

0

Please sign in to leave a comment.