The remote server returned an error: (400) Bad Request when trying to kick off a runbook using a step

Hi,

We have used a community step template “Run Octopus Deploy Runbook” which we have used for a long time without any problem, but all of a sudden, this step template causes an error:
NotSpecified: Error calling https://octopus.wur.nl/api/runbookRuns The remote server returned an error: (400) Bad Request. StatusCode: BadRequest
I have no idea what goes wrong, and can’t figure it out in the logfile, since it seems not to show the whole error:
At E:\Octopus Deploy\Octopus Worker Config-Logs\Work\20220603095721-202699-1020\Script.ps1:448 char:24
+ … kResponse = Invoke-OctopusApi -octopusUrl $defaultUrl -spaceId $space …
Is there any way to see, what exact call is being executed and what the exact error is, since “Bad Request. StatusCode: BadRequest” is ok, but not very pratical in showing what request is being performed.

Thanks in advance!

Best regards,
Jeffrey

Hi @jeffreywels ,

I would be happy to have a look at what’s going on.
Is it the Raw Logs that is showing the concatenated call that’s failing or does is only show the concatenated call on the Log Overview?

Either way, can you send through your Raw task logs from that deployment? Feel free to redact any private information.

Are there any updates available to the step template? Community Step Templates are updated outside of the Octopus Deploy update cycles and need to be updated manually. You can see if the step needs an update, by selecting the link to your step template from the step inside the project:

If an update is available, you will see a prompt to update.

Looking at the code of the step, there is only one line that matches the snippet above, which is the following:

$runbookResponse = Invoke-OctopusApi -octopusUrl $defaultUrl -spaceId $spaceId -apiKey $octopusApiKey -item $runbookBody -method "POST" -endPoint "runbookRuns"

Unfortunately, this leaves a lot of variables, with runbookBody consisting of in excess of ten variables on it’s own. We might be able to dig into these variables, using the “Evaluate Variables” function if updating doesn’t solve your issue and the Raw Logs don’t help at all.

Let me know how you go.

Regards,

Dane

Hi Dane,

I have already updated the Step Template, which was the first i did after getting this error.

I have send the raw log along
ServerTasks-202699.log.txt (97.0 KB)
And yes, the concatenated error shows in both the Log View as in the Raw log (which is why i can’t figure it out).

The strange thing is, the step seems to fail at several projects, though there is one project which does work, although the variables and settings are all the same. Even cloning this particular working step to another project causes it once again to fail in the other project.

Will this topic by private between you and I by the way? Since sending raw logs is a thing still :wink:

Best regards,
Jeffrey

Hey @jeffreywels,

Well those logs aren’t great on their own!

Even cloning this particular working step to another project causes it once again to fail in the other project.

This is also very odd.

As there may be some sensitive details in the next logs that I’m going to request from you, I’ll request you use the following link to upload your files.

However, please let us know by responding to this ticket, when you have uploaded some files.

Back to the issue:
Have you recently done an Octopus Server upgrade around the same time that you saw these issues?

I’m looking through the logs and although they aren’t super clear, I did notice the following:

11:57:23 Info | Use Published Snapshot Before Check: True
11:57:23 Info | Runbook Name Newman Tests - Grouptool
11:57:23 Info | Runbook Base Url: https://octopus.wur.nl
11:57:23 Info | Runbook Space Name:
11:57:23 Info | Runbook Environment Name: Server Environment
11:57:23 Info | Runbook Tenant Name:
11:57:23 Info | Wait for Finish: False
11:57:23 Info | Use Guided Failure: False
11:57:23 Info | Cancel run in seconds: 0
11:57:23 Info | Use Published Snapshot: True

If this is accurate, is seems like the “Space Name” is blank. Version 2022.1.2495 definitely requires the Spaces argument.

I’m assuming this is coming from the Runbooks variables.
Can you make sure your “Run Octopus Deploy Runbook” configuration includes the SpaceName variable.

Are you also able to publish a new runbook snapshot? The variables will likely not have changed, but it might be retaining information about the snapshot before Spaces were included.

I think this should be the first thing that you try. If this doesn’t get you closer to a solution, would you be able to return the results of the following API calls?

https://octopus.wur.nl/api/runbooks/Runbooks-245/runbookRuns/preview/Environments-61

You will need to update the Projects-X with the Project-ID of the Project with your runbook
https://octopus.wur.nl/api/Spaces-1/projects/Projects-X/runbooks/Runbooks-245/RunbookSnapshots-1930

https://octopus.wur.nl/api/Spaces-1/projects/Projects-X/runbooks/Runbooks-245/RunbookSnapshots-1930/Variables

Additionally, a HAR file might provide us with some additional information that could come in handy as well.

We should be able to get a decent idea of what is missing from those results.

Regards,

Hi Dane,

I checked the variable Space Name which was indeed and appeared to be required. Even though i filled in #{Octopus.Space.Name} it still doesn’t change the error (and the fact that the one project working is also without this setting, doesn’t give me the idea that that might be the culprit).

I tried to follow the url’s you requested but was only able to post the outcome of the first URL which i have uploaded using the link provided. The file is named Environments-61.json

When i try to follow the second and third link (for getting the runbooksnapshot information), it doesn’t show me what i’d expect. Up to https://octopus.wur.nl/api/Spaces-1/projects/Projects-883/runbooks/Runbooks-245/ it gives me an json output, but once i type /RunbookSnapshots-1930 or /RunbookSnapshots-1930/Variables, it gives me a “not found” page.

I have published the new snapshots also before trying.

And finally i made the requested HAR file (and uploaded it using the provided url): octopus.wur.nl_Archive [22-06-03 16-13-13].har

Hopefully this causes some clarity, but probably we need to have those runbooksnapshot and variables json aswell right?

Best regards,
Jeffrey

Hey Jeffrey,

Just jumping in for Dane as he is offline til Monday. Would you by chance be able to upload a deployment process JSON for us to the same location as the HAR? You can get this by going to the deployment process and clicking the 3 dots in the upper-right and clicking Download as JSON.

Please let me know if that’s something you’re okay with, and if so, when it’s done uploading so I can go take a look (we don’t get notifications for uploads).

Best,
Jeremy

Hi Jeremy,

I uploaded the deployment process json @ the provided link, named grouptool-process.json

Best regards,
Jeffrey

Hey Jeffrey,

Thanks for uploading that and letting me know.

That step template setup looks okay at first glance.

Can you please test two more urls in your browser for me?

Test 1: https://octopus.wur.nl/api/Spaces-1/projects/Projects-883/runbookSnapshots/RunbookSnapshots-1930

And

Test 2: https://octopus.wur.nl/api/Spaces-1/projects/Projects-883/runbookSnapshots/RunbookSnapshots-1930/variables

Please let me know if those both succeed or if you get any errors.

Best,
Jeremy

Hi Jeremy,

Both URLs hit, saved the JSON and uploaded it to the “support files portal”

Best regards,
Jeffrey

Hey Jeffrey,

Thanks for that.

We’re thinking that the JSON that gets sent might be malformed in some way. Would it be possible to add a line to the step template and use your own local copy in the process?

Could you add Write-Host $runbookBody on line 1058 so we can see what it’s using for that api call?

Please let me know.

Best,
Jeremy

Hi Jeremy,

Creating a copy and setting Write-Host $runbookBody, only resulted in a line of; System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry

I changed it to just show the variable $runbookBody on line 1058 and then it showed me all the variables in the array which is created starting from line 1039. These are the results;

Best regards,
Jeffrey

Sent you a DM