StackStorm/st2

PowerShell Script Runner not passing parameters to script

Open

#4730 aperta il 28 giu 2019

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Python (740 fork)batch import
buggood first issue

Metriche repository

Star
 (5794 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

SUMMARY

When a script is larger than the WINRM_MAX_CMD_LENGTH = 8192 the arguments are not being passed.

ISSUE TYPE
  • Bug Report
STACKSTORM VERSION

st2 3.0.1, on Python 2.7.5

OS / ENVIRONMENT / INSTALL METHOD

CENTOS7 per stackstorm install guide

STEPS TO REPRODUCE

winrm_windump.yaml

---
name: "winrm_windump"
description: "Action that runs arg dump"
enabled: true
entry_point: "windows/dump.ps1"
runner_type: "winrm-ps-script"
parameters:
  one:
    type: string
    default: "SOMEVALUE"
    required: true
    position: 0
    description: the first arguments

dump.ps1

param($one="notset")

write-host "one: $one"

### Enough content of script comments and code to get past the 8192 byte boundary
### ...
### ...

EXPECTED RESULTS
one: SOMEVALUE
ACTUAL RESULTS
one: notset

I could not get positional or named parameters to successfully make it to the PS script. The issue appears to be in the _run_ps_script function in winrm_base.py:

            ps = "& {%s}" % (tmp_script)  ###the ampersand and braces should be removed here
            if params:
                ps += " " + params
            return self._run_ps(ps)

Wrapping the braces around the script path is unnecessary and causes the arguments to be lost.

Quick workaround:

ps = "%s" % (tmp_script)

or simply:

ps = tmp_script

Guida contributor