Issue
Hello I am trying to pass this code to the command line everything works fine when I copy and paste it into my cmd shell by hand but when I use the exact command in my script it seems my command broke to multiple parts I don't know what's happening any idea?
python -m PyInstaller --specpath ./artifacts-repo/2022-10-09-174452/spec --distpath ./artifacts-repo/2022-10-09-174452/dist --workpath ./artifacts-repo/2022-10-09-174452/build --onefile ./codes/SayHello.py
above works fine when i copy and paste it in my CMD
bat "python -m PyInstaller --specpath ./artifacts-repo/${directoryName}/spec --distpath ./artifacts-repo/${directoryName}/dist --workpath ./artifacts-repo/${directoryName}/build --onefile ./codes/SayHello.py"
but when I try to pass that trough my pipline script it seems to shrinks!!! the result is bellow:
C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01>python -m PyInstaller --specpath ./artifacts-repo/2022-10-09-174452
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
[--add-data <SRC;DEST or SRC:DEST>]
[--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
[--hidden-import MODULENAME]
[--collect-submodules MODULENAME]
[--collect-data MODULENAME] [--collect-binaries MODULENAME]
[--collect-all MODULENAME] [--copy-metadata PACKAGENAME]
[--recursive-copy-metadata PACKAGENAME]
[--additional-hooks-dir HOOKSPATH]
[--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
[--key KEY] [--splash IMAGE_FILE]
[-d {all,imports,bootloader,noarchive}]
[--python-option PYTHON_OPTION] [-s] [--noupx]
[--upx-exclude FILE] [-c] [-w]
[-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">]
[--disable-windowed-traceback] [--version-file FILE]
[-m <FILE or XML>] [--no-embed-manifest] [-r RESOURCE]
[--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
[--win-no-prefer-redirects] [--argv-emulation]
[--osx-bundle-identifier BUNDLE_IDENTIFIER]
[--target-architecture ARCH] [--codesign-identity IDENTITY]
[--osx-entitlements-file FILENAME] [--runtime-tmpdir PATH]
[--bootloader-ignore-signals] [--distpath DIR]
[--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a]
[--clean] [--log-level LEVEL]
scriptname [scriptname ...]
pyinstaller: error: the following arguments are required: scriptname
C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01>/spec --distpath ./artifacts-repo/2022-10-09-174452
'/spec' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01>/dist --workpath ./artifacts-repo/2022-10-09-174452
'/dist' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01>/build --onefile ./codes/SayHello.py
'/build' is not recognized as an internal or external command,
operable program or batch file.
script returned exit code 1
Look the command it shrinked to 4 commands:
> python -m PyInstaller --specpath ./artifacts-repo/2022-10-09-174452
> /spec --distpath ./artifacts-repo/2022-10-09-174452 /dist --workpath
> ./artifacts-repo/2022-10-09-174452 /build --onefile
> ./codes/SayHello.py
Solution
Pipeline script the commands and variables not a problem (for jenkins)
BUT THE PROBLEM WAS: (OH MY GOD I am FILLING SO SILLY NOW -_- ) a couple of line upper i used a command for getting the date and time prefixes for making a directory and i echoed it like bellow:
directoryName = bat(returnStdout: true,script: '@echo %date:~-4,4%-%date:~-10,2%%date:~7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%')
the echo command add a \n after the command that was why my command split! it can be fix by using a .trim() after the command like below
directoryName = bat(returnStdout: true,script: '@echo %date:~-4,4%-%date:~-10,2%%date:~7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%').trim()
Answered By - Mohammad Taghadosi
Answer Checked By - Marilyn (JavaFixing Volunteer)