OctopusDeploy / Library

| Public | A repository of step templates and other community-contributed extensions to Octopus Deploy
Other
170 stars 500 forks source link

run-octopus-runbook failing to get machine ID #1492

Closed rukas closed 6 months ago

rukas commented 6 months ago

Step template

run-octopus-runbook

Step version

14

Octopus version

2023.4.8338

Step template parameter inputs

Runbook Base Url: https://server.domain (redacted server name) Runbook Space Name: Default Runbook Environment Name: Production Runbook Tenant Name:
Wait for Finish: True Use Guided Failure: True Cancel run in seconds: 1800 Use Published Snapshot: True Auto Approve Runbook Run Manual Interventions: No Auto Approve environment name to pull approvals from: Production Octopus runbook run machines: eus-svc-prd03,eus-svc-prd05,eus-svc-prd07,eus-svc-prd08

What happened

The step fails when trying to find a deployment target via the API. I believe there is an error where it isn't passing in the Octopus base URL.

When it tries to find a runbook it logs this:

No data to post or put, calling bog standard invoke-restmethod for https://server.domain/api/Spaces-1/projects/Projects-1163/runbooks?partialName=Start%20Services%20on%20Services%20Server&skip=0&take=100

When it tries to find the machine it runs this:

No data to post or put, calling bog standard invoke-restmethod for /api/machines?partialName=eus-svc-prd03&skip=0&take=100

It looks like it's missing https://server.domain in the invoke-restmethod call

Here is a the full log for the step run

                    |   == Running: Step 4: Run Start Services on Services Server Runbook ==
                    |   
                    |     == Running: Worker ==
12:16:18   Verbose  |       Octopus Server version: 2023.4.8338
12:16:18   Verbose  |       Environment Information:
                    |       IsRunningInContainer: False
                    |       MinimumThreadPoolCount: 400
                    |       MinimumCompletionPortThreads: 400
                    |       OperatingSystem: Microsoft Windows 10.0.17763
                    |       OsBitVersion: x64
                    |       Is64BitProcess: True
                    |       CurrentUser: eus-octopus-01\tdoctopus
                    |       MachineName: eus-octopus-01
                    |       ProcessorCount: 4
                    |       CurrentDirectory: C:\Windows\system32
                    |       TempDirectory: C:\Users\tdoctopus\AppData\Local\Temp\
                    |       HostProcessName: Octopus.Server
                    |       PID: 4112
12:16:18   Verbose  |       Leased worker eus-octowork-02 from pool Azure East US (lease WorkerTaskLeases-160483).
12:16:18   Verbose  |       Executing Run Start Services on Services Server Runbook (type Run a Script) on eus-octowork-02
12:16:18   Verbose  |       Determining ScriptService version to use
12:16:18   Verbose  |       Discovered Tentacle capabilities: IScriptService,IFileTransferService,IScriptServiceV2
12:16:18   Verbose  |       Using ScriptServiceV2
12:16:18   Verbose  |       RPC call retries are enabled. Retry timeout 150 seconds
12:16:20   Verbose  |       Acquiring isolation mutex RunningScript with NoIsolation in ServerTasks-962107
12:16:20   Verbose  |       Executable directory is C:\Windows\system32\WindowsPowershell\v1.0
12:16:20   Verbose  |       Executable name or full path: C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe
12:16:20   Verbose  |       Starting C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in working directory 'C:\Octopus\Work\TZGCJiE8t0KzdRP40Lnw' using 'OEM United States' encoding running as 'NT AUTHORITY\SYSTEM'
12:16:20   Verbose  |       Process C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in C:\Octopus\Work\TZGCJiE8t0KzdRP40Lnw exited with code 0
12:16:20   Verbose  |       Using Calamari.win-x64 26.0.16
12:16:20   Verbose  |       Determining ScriptService version to use
12:16:20   Verbose  |       Discovered Tentacle capabilities: IScriptService,IFileTransferService,IScriptServiceV2
12:16:20   Verbose  |       Using ScriptServiceV2
12:16:20   Verbose  |       RPC call retries are enabled. Retry timeout 150 seconds
12:16:26   Verbose  |       Acquiring isolation mutex RunningScript with NoIsolation in ServerTasks-962107
12:16:26   Verbose  |       Executable directory is C:\Windows\system32\WindowsPowershell\v1.0
12:16:26   Verbose  |       Executable name or full path: C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe
12:16:26   Verbose  |       Starting C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in working directory 'C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ' using 'OEM United States' encoding running as 'NT AUTHORITY\SYSTEM'
12:16:26   Verbose  |       Calamari Version: 26.0.16
12:16:26   Verbose  |       Environment Information:
12:16:26   Verbose  |       OperatingSystem: Microsoft Windows NT 10.0.17763.0
12:16:26   Verbose  |       OsBitVersion: x64
12:16:26   Verbose  |       Is64BitProcess: True
12:16:26   Verbose  |       CurrentUser: NT AUTHORITY\SYSTEM
12:16:26   Verbose  |       MachineName: eus-octowork-02
12:16:26   Verbose  |       ProcessorCount: 4
12:16:26   Verbose  |       CurrentDirectory: C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ
12:16:26   Verbose  |       TempDirectory: C:\Windows\TEMP\
12:16:26   Verbose  |       HostProcess: Calamari (8588)
12:16:26   Verbose  |       Performing variable substitution on 'C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1'
12:16:26   Verbose  |       Executing 'C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1'
12:16:26   Verbose  |       Setting Proxy Environment Variables
12:16:30   Verbose  |       Name                           Value
12:16:30   Verbose  |       ----                           -----
12:16:30   Verbose  |       PSVersion                      5.1.17763.5458
12:16:30   Verbose  |       PSEdition                      Desktop
12:16:30   Verbose  |       PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
12:16:30   Verbose  |       BuildVersion                   10.0.17763.5458
12:16:30   Verbose  |       CLRVersion                     4.0.30319.42000
12:16:30   Verbose  |       WSManStackVersion              3.0
12:16:30   Verbose  |       PSRemotingProtocolVersion      2.3
12:16:30   Verbose  |       SerializationVersion           1.1.0.1
12:16:30   Verbose  |       PowerShell Environment Information:
12:16:30   Verbose  |       OperatingSystem: Microsoft Windows NT 10.0.17763.0
12:16:30   Verbose  |       OsBitVersion: x64
12:16:30   Verbose  |       Is64BitProcess: True
12:16:30   Verbose  |       CurrentUser: NT AUTHORITY\SYSTEM
12:16:30   Verbose  |       MachineName: eus-octowork-02
12:16:30   Verbose  |       ProcessorCount: 4
12:16:30   Verbose  |       CurrentDirectory: C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ
12:16:30   Verbose  |       CurrentLocation: C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ
12:16:30   Verbose  |       TempDirectory: C:\Windows\TEMP\
12:16:30   Verbose  |       HostProcess: powershell (5552)
12:16:31   Verbose  |       TotalPhysicalMemory: 16776756 KB
12:16:31   Verbose  |       AvailablePhysicalMemory: 13281044 KB
12:16:31   Verbose  |       Invoking target script C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1 with  parameters.
12:16:31   Info     |       Wait for Finish Before Check: True
12:16:31   Info     |       Use Guided Failure Before Check: True
12:16:31   Info     |       Use Published Snapshot Before Check: True
12:16:31   Info     |       Runbook Name Start Services on Services Server
12:16:31   Info     |       Runbook Base Url: https://server.domain
12:16:31   Info     |       Runbook Space Name: Default
12:16:31   Info     |       Runbook Environment Name: Production
12:16:31   Info     |       Runbook Tenant Name:
12:16:31   Info     |       Wait for Finish: True
12:16:31   Info     |       Use Guided Failure: True
12:16:31   Info     |       Cancel run in seconds: 1800
12:16:31   Info     |       Use Published Snapshot: True
12:16:31   Info     |       Auto Approve Runbook Run Manual Interventions: No
12:16:31   Info     |       Auto Approve environment name to pull approvals from: Production
12:16:31   Info     |       Octopus runbook run machines: eus-svc-prd03,eus-svc-prd05,eus-svc-prd07,eus-svc-prd08
12:16:31   Info     |       Parent Task Id: ServerTasks-962107
12:16:31   Info     |       Parent Release Id:
12:16:31   Info     |       Parent Channel Id:
12:16:31   Info     |       Parent Environment Id: Environments-43
12:16:31   Info     |       Parent Runbook Id: Runbooks-804
12:16:31   Info     |       Parent Environment Name: Production
12:16:31   Info     |       Parent Release Number:
12:16:31   Info     |       Attempting to find Space with the name of Default
12:16:31   Verbose  |       No data to post or put, calling bog standard invoke-restmethod for https://server.domain/api/spaces?partialName=Default&skip=0&take=100
12:16:31   Info     |       Successfully found Default with id of Spaces-1
12:16:31   Info     |       Attempting to find Project with the name of Patching Automation
12:16:31   Verbose  |       No data to post or put, calling bog standard invoke-restmethod for https://server.domain/api/Spaces-1/projects?partialName=Patching%20Automation&skip=0&take=100
12:16:31   Info     |       Successfully found Patching Automation with id of Projects-1163
12:16:31   Info     |       Attempting to find Environment with the name of Production
12:16:31   Verbose  |       No data to post or put, calling bog standard invoke-restmethod for https://server.domain/api/Spaces-1/environments?partialName=Production&skip=0&take=100
12:16:31   Info     |       Successfully found Production with id of Environments-43
12:16:31   Info     |       Attempting to find Runbook with the name of Start Services on Services Server
12:16:31   Verbose  |       No data to post or put, calling bog standard invoke-restmethod for https://server.domain/api/Spaces-1/projects/Projects-1163/runbooks?partialName=Start%20Services%20on%20Services%20Server&skip=0&take=100
12:16:32   Info     |       Successfully found Start Services on Services Server with id of Runbooks-843
12:16:32   Info     |       The last published snapshot for Start Services on Services Server is RunbookSnapshots-3098
12:16:32   Info     |       Use published snapshot set to true, using the published runbook snapshot.
12:16:32   Info     |       Trying the new preview step
12:16:32   Verbose  |       No data to post or put, calling bog standard invoke-restmethod for https://server.domain/api/Spaces-1/runbookSnapshots/RunbookSnapshots-3098/runbookRuns/preview/Environments-43?includeDisabledSteps=true
12:16:32   Verbose  |       Translating eus-svc-prd03 to an Id.  First checking to see if it is already an Id.
12:16:32   Info     |       Attempting to find Deployment Target with the name of eus-svc-prd03
12:16:32   Verbose  |       No data to post or put, calling bog standard invoke-restmethod for /api/machines?partialName=eus-svc-prd03&skip=0&take=100
12:16:32   Verbose  |       System.UriFormatException: Invalid URI: The hostname could not be parsed.
12:16:32   Verbose  |       at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
12:16:32   Verbose  |       at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri)
12:16:32   Verbose  |       at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.PrepareUri(Uri uri)
12:16:32   Verbose  |       at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri)
12:16:32   Verbose  |       at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
12:16:32   Verbose  |       at System.Management.Automation.CommandProcessor.ProcessRecord()
12:16:32   Error    |       OperationStopped: There was an error calling the Octopus API please check the log for more details
12:16:32   Error    |       At C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1:125 char:5
12:16:32   Error    |       +     Throw "There was an error calling the Octopus API please check th ...
12:16:32   Error    |       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12:16:32   Error    |       at Invoke-OctopusApi, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1: line 125
12:16:32   Error    |       at Get-OctopusItemFromListEndpoint, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1: line 207
12:16:32   Error    |       at Get-MachineIdsFromMachineNames, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1: line 237
12:16:32   Error    |       at Get-RunbookSpecificMachines, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1: line 622
12:16:32   Error    |       at <ScriptBlock>, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Script.ps1: line 1060
12:16:32   Error    |       at <ScriptBlock>, <No file>: line 1
12:16:32   Error    |       at <ScriptBlock>, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Octopus.FunctionAppenderContext.ps1: line 244
12:16:32   Error    |       at <ScriptBlock>, C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ\Bootstrap.Octopus.FunctionAppenderContext.ps1: line 4119
12:16:32   Error    |       at <ScriptBlock>, <No file>: line 1
12:16:32   Error    |       at <ScriptBlock>, <No file>: line 1
12:16:32   Verbose  |       Process C:\Windows\system32\WindowsPowershell\v1.0\PowerShell.exe in C:\Octopus\Work\9NVaKukD0aP8TxMF4p6KQ exited with code 1
12:16:32   Verbose  |       Updating manifest with output variables
12:16:32   Verbose  |       Updating manifest with action evaluated variables
12:16:32   Verbose  |       Updating manifest with output variables
12:16:32   Verbose  |       Updating manifest with action evaluated variables
12:16:32   Error    |       The remote script failed with exit code 1
                    |     

Reproduction steps

Use the Machine List input variable

More Information

No response

harrisonmeister commented 6 months ago

Hey @rukas

Thank you for raising this issue. I've raised a PR - #1493 that should resolve this.

Best wishes

rukas commented 6 months ago

Great, thanks @harrisonmeister !

harrisonmeister commented 6 months ago

@rukas - version 15 is now available for this step, and I have just run a test and it should now work :)

rukas commented 6 months ago

Thanks for the quick turnaround on this! I've tested it and it works as expected now!

harrisonmeister commented 6 months ago

Thanks for the quick turnaround on this! I've tested it and it works as expected now!

You're very welcome!