Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Command failure is ignored when embedded inside PDQ

For the deployment of software developed for internal company usage I simply pack all files into a zip, copy that over to the deployment repository, and during deployment run a script that copies the content of the zip marked as latest version to the intended computers.

Now I wanted that step to fail with the errorlevel of the command that was run and failed in the script. When I insert the batch and simply call it, this works as intended: script fails => step fails => error code get's shown in the status of the step, parts of the deployment are marked as failed.

If I insert the content of the batch file as command into the appropriate step the step finished successfully - even though the script itself fails and half of the work isn't even done. The whole deployment is thus marked as successful.

Any idea on what i'm doing wrong?

 

Here's the batch code I use for deployment:

:: installation
if exist "%SOFTWARE_PATH%\%APP_ID%-%APP_VERSION%.zip" (
Setlocal EnableDelayedExpansion

:: finish running app...
%SYSTEMROOT%\system32\taskkill.exe /f /im %APP_BINARY%
:: ...wait for app to finish
timeout 1
:: remove existing version
if exist "%INSTALL_PATH%" (rd /s /q "%INSTALL_PATH%" || exit /b !errorlevel!)

mkdir "%INSTALL_PATH%" || exit /b !errorlevel!
:: copy new version
"%DEPLOY_PATH%\7za" x -y "%SOFTWARE_PATH%\%APP_ID%-%APP_VERSION%.zip" -o"%INSTALL_PATH%" || exit /b !errorlevel!
:: copy license files
if exist "%LICENSE_PATH%\%APP_ID%.zip" ("%DEPLOY_PATH%\7za" x -y "%LICENSE_PATH%\%APP_ID%.zip" -o"%INSTALL_PATH%" || exit /b !errorlevel!)

:: register application
if exist "%INSTALL_PATH%\setup.reg" (reg import "%INSTALL_PATH%\setup.reg" || exit /b !errorlevel!)
:: create desktop link to binary
if exist "%INSTALL_PATH%\%APP_BINARY%" (powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%PUBLIC%\Desktop\%APP_NAME%.lnk');$s.TargetPath='%INSTALL_PATH%\%APP_BINARY%';$s.Save()" || exit /b !errorlevel!)
Endlocal
)

 

On another note: originally I've unpacked the zip's content (line 27) using the scripting host inside a powershell command:

powershell "$shell=New-Object -com Shell.Application;$dest=$shell.Namespace('%INSTALL_PATH%');foreach($item in $shell.Namespace('%SOFTWARE_PATH%\%APP_ID%-%APP_VERSION%.zip').Items()){$dest.CopyHere($item, 0x14)}" || exit /b !errorlevel!

This works fine as long as i start this using administrative and elevated rights from the console. But whenever i call this script from pdq deploy the execution stops right there without any output at all.

Any ideas on that as well?

0

Comments

3 comments
Date Votes
  • This is not related to the bug you found but rather a hint for a different approach.

    You can create a selfextracting archive using winrar or 7zip, which then executes a batch or executable. I suggest you create 2 packages x86 and x64 including the selfextractor engine, as the batches behave differently in each enviroment.

    0
  • This is quite a nice approach. I like it. :)

    Although a separation is not a necessary, since I'm compiling my programs using AnyCPU (or more recently using x64 only compilation) as target platform with a preference for x64 and the batch files contain switches like:

    if defined ProgramFiles(x86) (
    ... x64 specific part ...
    ) else (
    ... x32 specific part ...
    )

    whenever I use bitness specific commands (like copy to ProgramFiles, reg manipulation, etc.).

    Though I can see where your advice comes into play when deploying external software that was compiled targeting a specific bitness.

    0
  • You are welcome. Though I see here a small problem. As PDQ Deploy is a 32bit application, its probably starting the 32bit version of CMD to execute the batch. Hence the diferences.

    But this has to be answered by the  PDQ guys, as i dont see in to the insides of PDQ Deploy.

    0