jenkins bat命令在使用变量embedded [closed]后转到下一行

dojqjjoe  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(343)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受答案。

这个问题是由一个打字错误或一个无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
18天前关闭。
Improve this question
你好,我正试图将此代码传递到命令行,当我手动将其复制并粘贴到我的cmd shell中时,一切都正常,但当我在脚本中使用确切的命令时,我的命令似乎分成了多个部分,我不知道发生了什么,有什么想法吗?

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

当我复制并粘贴到我的CMD中时,上面的工作正常

bat "python -m PyInstaller --specpath ./artifacts-repo/${directoryName}/spec --distpath ./artifacts-repo/${directoryName}/dist --workpath ./artifacts-repo/${directoryName}/build --onefile ./codes/SayHello.py"

但是当我试着通过那个槽时,我流水线脚本似乎缩小了!2!3结果是:

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

看起来这个命令它缩小到4个命令:

> 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
5kgi1eie

5kgi1eie1#

管道脚本的命令和变量不是一个问题(对于Jenkins)
但问题是:(哦,我的上帝,我现在填充这么愚蠢-_-)一对夫妇的行上,我用了一个命令,以获得日期和时间前缀,使一个目录,我呼应它如风箱:

directoryName = bat(returnStdout: true,script: '@echo %date:~-4,4%-%date:~-10,2%%date:~7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%')

echo命令在命令后添加一个\n这就是为什么我的命令分裂!它可以通过在命令后使用一个.trim()来修复,如下所示

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()

相关问题