I would like to trigger new job for runner but I get bed request. How to do it correctly?
From C# code → I would like to create job will go to runner and execute → without choose project/branch/create new job but api go to runner
public async Task<string> TriggerCommandOnRunner(int runnerId, string command)
{
try
{
// Create a new job to run the specified command on the GitLab Runner.
var jobRequest = new
{
job = new
{
runner_id = runnerId,
script = command
}
};
var content = new StringContent(JsonSerializer.Serialize(jobRequest), Encoding.UTF8,
"application/json");
var response = await _httpClient.PostAsync($"{_gitLabUrl}jobs/request", content);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
// Parse and process the responseBody as needed.
return responseBody;
}
return await Task.FromResult("failed with connection");
}
catch (Exception ex)
{
return await Task.FromResult($"failed {ex.Message}");
}
return string.Empty;
}