PS script not running well only in Rundeck

98 views
Skip to first unread message

mezam

unread,
Jun 1, 2024, 12:04:39 PMJun 1
to rundeck-discuss
Hello, I have a very weird problem with a PS script that runs fine elsewhere but not in RD anymore. It has been working fine for months (in RD) and now it throws weird errors:

At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:45 char:3
+ td, th { border:1px solid black;
+   ~
Missing argument in parameter list.
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:49 char:6
+ table, tr, td, th { padding: 2px; margin: 0px }
+      ~
Missing argument in parameter list.
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:65 char:79
+ ... nvertTo-HTML -Head $head -Body $html.InnerXml -PostContent "<h6>Creat ...
+                                                                 ~
The '<' operator is reserved for future use.
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:65 char:91
+ ... Head $head -Body $html.InnerXml -PostContent "<h6>Created and Sent by ...
+                                                               ~~~
Unexpected token 'and' in expression or statement.
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:65 char:124
+ ... Xml -PostContent "<h6>Created and Sent by Rundeck - $(Get-Date)</h6>"
+                                                                    ~
The '<' operator is reserved for future use.
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:81 char:82
+ ... or -Message "Connection from Rundeck Server to vCenter server failed"
+                                                                         ~
The string is missing the terminator: ".
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:54 char:9
+ .paused {color: #FF8000 }
+         ~
Missing closing '}' in statement block or type definition.
At C:\WINDOWS\TEMP\36-10835-localhost-dispatch-script.tmp.ps1:53 char:10
+ .pending {color: #DF01D7 }
+          ~
Missing closing '}' in statement block or type definition.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingArgument
 
Result: 1
Failed: NonZeroResultCode: Result code was 1
Execution failed: 10835 in project RSM-Tasks: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [localhost: NonZeroResultCode: Result code was 1 + {dataContext=MultiDataContextImpl(map={ContextView(step:1, node:localhost)=BaseDataContext{{exec={exitCode=0}}}, ContextView(node:localhost)=BaseDataContext{{exec={exitCode=0}}}}, base=null)} ]}, Node failures: {localhost=[NonZeroResultCode: Result code was 1 + {dataContext=MultiDataContextImpl(map={ContextView(step:1, node:localhost)=BaseDataContext{{exec={exitCode=0}}}, ContextView(node:localhost)=BaseDataContext{{exec={exitCode=0}}}}, base=null)} ]}, status: failed]

the first line of errors refers to a block of code which is this:

   $head = @"
<Title>$ReportTitle</Title>
<style>
body { background-color:#FFFFFF;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:black;
background-color:#f7b359; }
table, tr, td, th { padding: 2px; margin: 0px }
table { width:95%;margin-left:5px; margin-bottom:20px;}
.stopped {color: Red }
.running {color: Green }
.pending {color: #DF01D7 }
.paused {color: #FF8000 }
.other {color: Black }
</style>
<br>
<H2>$ReportTitle</H2>
"@

if I copy the code in VS Code it works fine. I recreated the job from scratch but same problem. I don't get it!! Other jobs run fine... any hint? I also rebooted  the server. It's a Rundeck4.17.02023-09-25basilisk sandybrown flag on Windows 2019

rac...@rundeck.com

unread,
Jun 3, 2024, 9:44:29 AMJun 3
to rundeck-discuss
Hi,

It seems to be an error due to a script/target server modification. Do you see any clue after running that job in debug mode?

Regards.

mezam

unread,
Jun 5, 2024, 5:23:04 AMJun 5
to rundeck-discuss
hello again, thanks Reiner as usual.. I've attached a file with the debug output. The lines that seem to be pointing at something maybe are these below but I cannot find anything in the script that is syntactically incorrect:


Executing 'cmd.exe' with arguments:

'/c'

'del'

'C:\WINDOWS\TEMP\154-10955-localhost-dispatch-script.tmp.ps1'



The ' characters around the executable and arguments are

not part of the command.
Execute:Java13CommandLauncher: Executing 'cmd.exe' with arguments:

'/c'

'del'

'C:\WINDOWS\TEMP\154-10955-localhost-dispatch-script.tmp.ps1'



The ' characters around the executable and arguments are

not part of the command.



debug.txt

rac...@rundeck.com

unread,
Jun 5, 2024, 12:58:06 PMJun 5
to rundeck-discuss

Hi mezam,

It appears that you are running a cmd.exe command that calls the PowerShell script. Is that job executing a " Local Command" step or a "Command" step?

1) Test using the "Command" step instead of "Local Command", or 2) run your PS script using the "Script Step". Consider the following example:

- defaultTab: nodes description: '' executionEnabled: true id: 849a24f4-cb99-4946-9e18-a3a0fb7fdcd6 loglevel: INFO name: TestScriptWindows nodeFilterEditable: false nodefilters: dispatch: excludePrecedence: true keepgoing: false rankOrder: ascending successOnEmptyNodeFilter: false threadcount: '1' filter: 'name: windows ' nodesSelectedByDefault: true plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - args: '''Hello!'' ''happy''' fileExtension: .ps1 interpreterArgsQuoted: true script: |- param( [Parameter()] [String]$message, [String]$emotion ) Write-Output $message Write-Output "I am $emotion" scriptInterpreter: powershell.exe keepgoing: false strategy: node-first uuid: 849a24f4-cb99-4946-9e18-a3a0fb7fdcd6

Regards!

mezam

unread,
Jun 16, 2024, 12:48:13 PMJun 16
to rundeck-discuss
Thanks Reiner and sorry for replying late, as I'm on holiday. The step is and was always a script step, screenshots attached. So I don't get where the cmd.exe is coming from
2024-06-16_184720.jpg
2024-06-16_184344.jpg

rac...@rundeck.com

unread,
Jun 17, 2024, 11:46:23 AMJun 17
to rundeck-discuss
I see, Can you share your Windows node definition entry? (maybe defined in an XML or YAML file). Also, can you share a reproducible example script to test it?

Regards.

mezam

unread,
Jun 24, 2024, 8:43:21 AM (9 days ago) Jun 24
to rundeck-discuss
Hello Reiner, back in the office today.. 
this script does not use any node definition, it has in it the name of a vmware vcenter server (set as a secret) and it runs a routing check). The result of the check is sent via email. I've tried to prepare a reproducible script to test, but I can see that it fails on any subsection of the script. For instance this code below is the very beginning of the script:


# vcenter part
$vcPassword = ConvertTo-SecureString "@option.vCenterPassword@" -AsPlainText -Force
$vcCred = New-Object System.Management.Automation.PSCredential ("@option.vCenterUsername@", $vcPassword)
connect-VIServer -Server "@option.vcName@" -Credential $vcCred
if($global:defaultviserver.isConnected){
   
    $snapshots = Get-VM | Get-Snapshot
    $date = (Get-Date).tostring("dd-MM-yyyy")
    if (!$snapshots) {
        $ReportTitle = "No snapshots found. Enjoy the weekend!"
    }
    else {
        $ReportTitle = "Please review the following snapshots before leaving for the weekend:"
        $data = @()
    foreach ($snap in $snapshots) {
        $snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1 | Where-Object { $_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot' }  
        if ($snap.PowerState -eq "PoweredOn") {
            $memory = $True
        }
        else {
            $memory = $False
        }
        $report = "" | Select-Object -Property VM, Date, CreatedBy, SizeGB, MemorySnapshot
        $report.VM = $snap.VM
        $report.Date = $snap.Created.Date.ToString("dd-MM-yyyy")
        if ($null -ne $snapevent) {
            $report.CreatedBy = $snapevent.UserName
        }
        else { $report.CreatedBy = "No events to read from" }
        $report.SizeGB = $snap.SizeGB.ToString("#0.##")
        $report.MemorySnapshot = $memory
        $data += $report
               
    }
}

Disconnect-VIServer -Server $global:DefaultVIServer -Force -Confirm:$false



and it fails with this error (attached)
error.jpg

mezam

unread,
Jun 24, 2024, 8:46:09 AM (9 days ago) Jun 24
to rundeck-discuss
I've noticed another script now that fails with this type of error:

The string is missing the terminator: ".
but I can't figure out what is happening, most likely related to this..

rac...@rundeck.com

unread,
Jun 24, 2024, 12:27:59 PM (8 days ago) Jun 24
to rundeck-discuss
Hi,

Another approach is to check this. It seems the same issue.

Regards.

mezam

unread,
Jun 25, 2024, 4:05:22 AM (8 days ago) Jun 25
to rundeck-discuss
many thanks Reiner, that was it! However, just by adding an extra @ to the existing ones didn't work. I had to replace also all double quotes to the rundeck variable into single quotes. From this:

"@option.vcName@"

to

'@option.vcName@'

I still don't understand why this behaviour changed, considering that rundeck was not updated nor upgraded. But thanks again anyway!

mezam

unread,
Jun 25, 2024, 4:08:27 AM (8 days ago) Jun 25
to rundeck-discuss
also I had to replace the splatting used in this command:

Send-MailMessage @params

to the full details after the command. Do you know if this limitation has been addressed in later versions after 4.17?

Reply all
Reply to author
Forward
0 new messages