Jack
Jack

Reputation: 491

windows batch multiline command?

Can someone please tell me what in the following command line not correct is?

${WORKSPACE} = C:\jenkins\workspace\compile-job

cmd.exe /s /c START /b /BELOWNORMAL
mkdir C:\jenkins\workspace\old
move /Y %WORKSPACE%\* C:\jenkins\workspace\old
rmdir /q /s C:\jenkins\workspace\old

Upvotes: 1

Views: 5476

Answers (1)

Joey
Joey

Reputation: 354416

Plenty.

  1. ${WORKSPACE} = ... is neither cmd nor PowerShell syntax, it's nothing sensible. Use

    set WORKSPACE=C:\jenkins\workspace\compile-job
    

    instead.

  2. You can have multi-line commands by ending the line before with ^. However you want to execute three commands instead of just one. One option would be to write a batch file to execute (certainly the cleanest approach). But since you already have one, you can get clever:

    if not %1==x (
      START "" /b /BELOWNORMAL %0 x
      goto :eof
    )
    
    set WORKSPACE=C:\jenkins\workspace\compile-job
    
    mkdir C:\jenkins\workspace\old
    move /Y %WORKSPACE%\* C:\jenkins\workspace\old
    rmdir /q /s C:\jenkins\workspace\old
    

    This will execute the batch file again but with an argument and within the batch we look whether that argument is present and do the work or not.

Upvotes: 1

Related Questions