Single quotes addes when running a job option with backslash

35 views
Skip to first unread message

Mazz

unread,
Nov 23, 2021, 4:44:48 PM11/23/21
to rundeck-discuss
Hello all,

I created a very simple batch job on a Windows host with a text option named DB and the remote command C:\rundeck\test.bat ${option.DB} The batch script has just the following line : echo %1

If I run this job with an option containing a backslash (test1\test2 in this example) it adds automatically unwanted single quotes :

C:\Rundeck>echo 'test1\test2'
'test1\test2'

Debug Mode :

[workflow] Begin step: 1,NodeDispatch
1: Workflow step executing: CommandItem{command=[2 words]}
preparing for sequential execution on 1 nodes
Executing command on node: localhost, NodeEntryImpl{tags=[], attributes={nodename=localhost, hostname=localhost, osVersion=10.0, osFamily=windows, osArch=amd64, description=Rundeck server node, osName=Windows 10}, project='null'}
[workflow] beginExecuteNodeStep(localhost): NodeDispatch: CommandItem{command=[2 words]}
using charset: null
Current OS is Windows 10
Adding reference: ant.PropertyHelper
Project base dir set to: C:\Rundeck
Setting environment variable: RD_JOB_ID=d367a203-a84d-4189-8931-6bad1cbd19c1
Setting environment variable: RD_JOB_USERNAME=admin
Setting environment variable: RD_OPTION_DB=test1\test2
Setting environment variable: RD_NODE_HOSTNAME=localhost
Setting environment variable: RD_JOB_URL=http://localhost:4440/project/TOTO/execution/follow/12
Setting environment variable: RD_JOB_PROJECT=TOTO
Setting environment variable: RD_JOB_NAME=testtt
Setting environment variable: RD_NODE_OS_ARCH=amd64
Setting environment variable: RD_NODE_OS_VERSION=10.0
Setting environment variable: RD_NODE_NAME=localhost
Setting environment variable: RD_JOB_THREADCOUNT=1
Setting environment variable: RD_JOB_RETRYATTEMPT=0
Setting environment variable: RD_JOB_USER_NAME=admin
Setting environment variable: RD_JOB_LOGLEVEL=DEBUG
Setting environment variable: RD_NODE_OS_NAME=Windows 10
Setting environment variable: RD_JOB_SERVERUUID=4b89944a-5397-498a-a286-12ca7a841480
Setting environment variable: RD_NODE_OS_FAMILY=windows
Setting environment variable: RD_JOB_EXECID=12
Setting environment variable: RD_NODE_USERNAME=
Setting environment variable: RD_NODE_TAGS=
Setting environment variable: RD_JOB_RETRYPREVEXECID=0
Setting environment variable: RD_JOB_SERVERURL=http://localhost:4440/
Setting environment variable: RD_JOB_EXECUTIONTYPE=user
Setting environment variable: RD_JOB_WASRETRY=false
Setting environment variable: RD_JOB_SUCCESSONEMPTYNODEFILTER=false
Setting environment variable: RD_JOB_RETRYINITIALEXECID=0
Setting environment variable: RD_NODE_DESCRIPTION=Rundeck server node
Executing 'cmd.exe' with arguments: '/c' 'C:\rundeck\test.bat' ''test1\test2'' The ' characters around the executable and arguments are not part of the command.
Execute:Java13CommandLauncher: Executing 'cmd.exe' with arguments: '/c' 'C:\rundeck\test.bat' ''test1\test2'' The ' characters around the executable and arguments are not part of the command.
C:\Rundeck>echo 'test1\test2'
'test1\test2'
Setting project property: 1637703827363.node.localhost.LocalNodeExecutor.result -> 0
[workflow] finishExecuteNodeStep(localhost): NodeDispatch: Succeeded
1: Workflow step finished, result: Dispatch successful (1 nodes)
[workflow] Finish step: 1,NodeDispatch

What can I do to prevent this behaviour ? If I run echo test1\test2 directly against the node the quotes are not present so it must be something with the options but I have no clue on this.

Regards,

Clem

rac...@rundeck.com

unread,
Nov 24, 2021, 7:35:54 AM11/24/21
to rundeck-discuss
Hi Clem,

Just to discard, Did you check this? If so, could you provide the job definition example to test?

Greetings.

Mazz

unread,
Nov 24, 2021, 11:40:53 AM11/24/21
to rundeck-discuss
Hi,

I'm using Command step so I think it does not apply to my case.

Here the job definition :

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: d367a203-a84d-4189-8931-6bad1cbd19c1
  loglevel: INFO
  name: testtt
  nodeFilterEditable: false
  options:
  - name: DB
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: C:\rundeck\test.bat ${option.DB}
    keepgoing: false
    strategy: node-first
  uuid: d367a203-a84d-4189-8931-6bad1cbd19c1

rac...@rundeck.com

unread,
Nov 24, 2021, 1:08:45 PM11/24/21
to rundeck-discuss

Hi Clem,

I reproduced your issue, try calling the .bat file using powershell.exe as an interpreter, I left a Job Definition example (calling an example .bat script in three ways):

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: b8fbe82e-02ca-423e-9d23-cbd0de7c317c
  loglevel: INFO
  name: HelloWorld
  nodeFilterEditable: false
  options:
  - name: param1
    value: hello\world
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - description: Using command step
      exec: powershell.exe C:\rundeck\script.bat ${option.param1}
    - args: ${option.param1}
      description: Using external script step
      expandTokenInScriptFile: true
      fileExtension: .bat
      interpreterArgsQuoted: false
      scriptInterpreter: powershell.exe
      scriptfile: C:\rundeck\script.bat
    - description: using inline script step
      script: '@echo hello %1 @option.param1@'
    keepgoing: false
    strategy: node-first
  uuid: b8fbe82e-02ca-423e-9d23-cbd0de7c317c

That works with this .bat example script:

@echo hello %1

Check the result here.

Hope it helps!

Mazz

unread,
Nov 25, 2021, 2:34:29 AM11/25/21
to rundeck-discuss
Hi,

It's working flawlessly now, thanks a lot for your help !

Clem

rac...@rundeck.com

unread,
Nov 25, 2021, 8:27:37 AM11/25/21
to rundeck-discuss
Great Clem! Happy to help!
Reply all
Reply to author
Forward
0 new messages