-
Type:
Task
-
Status: Closed
-
Priority:
Normal
-
Resolution: Won't Do
-
Affects Version/s: BOLT 1.11.0
-
Fix Version/s: None
-
Component/s: Windows
-
Template:customfield_10700 296554
-
Team:Bolt
-
Sprint:Bolt Ready for Grooming
-
Release Notes:Known Issue
-
Release Notes Summary:When passing complex arguments to tasks with --params, JSON strings (typically created with the ConvertTo-Json cmdlet) might require additional escaping. In some cases, you can use the stop parsing symbol --% as a workaround.
-
QA Risk Assessment:Needs Assessment
BOLT-159 introduced a change to simplify argument passing from PowerShell when dealing with nested quotes.
The change does improve the case mentioned, such that users can now use a simpler invocation like the following (rather than using """ themselves):
bolt command run 'echo "hi from $(hostname)"' --modulepath . --nodes winrm://localhost -u Administrator -p Qu@lity! --no-ssl
|
However, there are still cases where using more complex argument passing does not work properly due to not all values being escaped correctly for Ruby.
In an ideal situation, a complex object should be serializable to a JSON string, which can then be passed directly like --params ($myobject | ConvertTo-Json). Note that we will likely need a new PowerShell helper to serialize the values as desired, because of the way ConvertTo-Json handles certain types. For instance, more complex values like RegEx, IO.FileInfo and DateTime do not serialize in a way that's friendly to Bolt, requiring that ToString() be called first.
PS C:\cygwin64\home\Administrator> [DateTime]::Now | ConvertTo-Json
|
{
|
"value": "\/Date(1550588884351)\/",
|
"DateTime": "Tuesday, February 19, 2019 3:08:04 PM"
|
}
|
|
|
PS C:\cygwin64\home\Administrator> [DateTime]::Now.ToString() | ConvertTo-Json
|
"2/19/2019 3:08:07 PM"
|
|
|
PS C:\cygwin64\home\Administrator> [IO.FileInfo]'c:\windows' | ConvertTo-Json
|
{
|
"Name": "windows",
|
"Length": null,
|
"DirectoryName": "c:\\",
|
"Directory": {
|
"Name": "c:\\",
|
"FullName": "c:\\",
|
"Parent": null,
|
"Exists": true,
|
"Root": {
|
"Name": "c:\\",
|
"FullName": "c:\\",
|
"Parent": null,
|
"Exists": true,
|
"Root": "c:\\",
|
"Extension": "",
|
"CreationTime": "\/Date(1536991766317)\/",
|
"CreationTimeUtc": "\/Date(1536991766317)\/",
|
"LastAccessTime": "\/Date(1550181187575)\/",
|
"LastAccessTimeUtc": "\/Date(1550181187575)\/",
|
"LastWriteTime": "\/Date(1550181186731)\/",
|
"LastWriteTimeUtc": "\/Date(1550181186731)\/",
|
"Attributes": 22
|
},
|
"Extension": "",
|
"CreationTime": "\/Date(1536991766317)\/",
|
"CreationTimeUtc": "\/Date(1536991766317)\/",
|
"LastAccessTime": "\/Date(1550181187575)\/",
|
"LastAccessTimeUtc": "\/Date(1550181187575)\/",
|
"LastWriteTime": "\/Date(1550181186731)\/",
|
"LastWriteTimeUtc": "\/Date(1550181186731)\/",
|
"Attributes": 22
|
},
|
"IsReadOnly": false,
|
"Exists": false,
|
"FullName": "c:\\windows",
|
"Extension": "",
|
"CreationTime": "\/Date(1536991766473)\/",
|
"CreationTimeUtc": "\/Date(1536991766473)\/",
|
"LastAccessTime": "\/Date(1550170740568)\/",
|
"LastAccessTimeUtc": "\/Date(1550170740568)\/",
|
"LastWriteTime": "\/Date(1550170740568)\/",
|
"LastWriteTimeUtc": "\/Date(1550170740568)\/",
|
"Attributes": 16,
|
"Mode": "d-----",
|
"VersionInfo": null,
|
"BaseName": "windows",
|
"Target": [
|
|
|
],
|
"LinkType": null
|
}
|
|
|
PS C:\cygwin64\home\Administrator> ([IO.FileInfo]'c:\windows').ToString() | ConvertTo-Json
|
"c:\\windows"
|
|
|
PS C:\cygwin64\home\Administrator> [RegEx]'.*' | ConvertTo-Json
|
{
|
"Options": 0,
|
"MatchTimeout": {
|
"Ticks": -10000,
|
"Days": 0,
|
"Hours": 0,
|
"Milliseconds": -1,
|
"Minutes": 0,
|
"Seconds": 0,
|
"TotalDays": -1.1574074074074074E-08,
|
"TotalHours": -2.7777777777777776E-07,
|
"TotalMilliseconds": -1,
|
"TotalMinutes": -1.6666666666666667E-05,
|
"TotalSeconds": -0.001
|
},
|
"RightToLeft": false
|
}
|
|
|
PS C:\cygwin64\home\Administrator> ([RegEx]'.*').ToString() | ConvertTo-Json
|
".*"
|
A command that should work when this change is completed is
bolt command run 'Get-Counter "\Processor(_Total)\% Processor Time"' --modulepath . --nodes winrm://localhost -u Administrator -p *redacted* --no-ssl
|
A variant of the following as a task which accepts JSON parameters should also be acceptable (something like the following)
$names = @(
|
|
|
'\memory\% committed bytes in use',
|
'\Processor(_Total)\% Processor Time',
|
'\Processor(_Total)\% User Time'
|
)
|
$counters = @{"names" = $names}
|
|
|
bolt task run foo::windows --modulepath . --nodes winrm://localhost -u Administrator -p *redacted* --no-ssl --params ($counters | ConvertTo-Json -Compress)
|