Bash jenkins 中用于签署应用程序的脚本行为错误

Bash script in jenkins for signing application behaves wrong

我正在尝试设置 Jenkins 来构建和部署我正在处理的应用程序之一。 我创建了一个对应用程序进行签名的阶段。 它确实签署了应用程序,但在它尝试将不同的选项作为单独的命令执行之后立即。

13:07:16  + bash
13:07:16  + cd Wrap.UI
13:07:16  + 'C:\Program Files (x86)\Windows Kits\bin.0.19041.0\x86\signtool.exe' sign /f './Service.pfx' /p password ./bin/x64/Test/Wrap.UI.exe
13:07:16  Done Adding Additional Store
13:07:16  Successfully signed: ./bin/x64/Test/Wrap.UI.exe

13:07:16  
13:07:16  Number of files successfully Signed: 1

13:07:16  Number of errors: 4

13:07:16  SignTool Error: File not found: F:/

13:07:16  SignTool Error: This file format cannot be signed because it is not recognized.
13:07:16  SignTool Error: An error occurred while attempting to sign: ./Service.pfx

13:07:16  SignTool Error: File not found: P:/

13:07:16  SignTool Error: File not found: password

Jenkins 脚本中的字符串如下所示

    sh '''
bash
                        cd Wrap.UI
                        "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86\signtool.exe" sign /f "./Service.pfx" /p password ./bin/x64/''' + CONFIGURATION + '''/Wrap.UI.exe
                        cd ..
                    '''

对于代码部分的奇怪间距,我深表歉意。

我猜我需要以某种方式封装命令及其参数,但我对 bash 脚本不是很熟悉,需要一些帮助。

如果您使用 Windows,也许尝试使用 bat 命令而不是 sh 命令。 (我从没想过我会建议这个,但看起来你的 sh 支持有问题。)

bat """
    cd Wrap.UI
    "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86\signtool.exe" sign /f "./Service.pfx" /p password ./bin/x64/${CONFIGURATION}/Wrap.UI.exe
"""

另请注意,最后不需要cd ..;命令 运行 在单独的环境中,其当前工作目录不会反映回父目录。

切线地说,孤独的 bash 没有做任何有用的事情。如果你想 运行 Bash 中的命令而不是 sh,语法是 sh '''bash -c 'commands; more commands'; '''。但是这里不需要 Bash; cdbashsh 中的行为相同,除此之外,您只是 运行 一个外部 Windows 命令。单独的 bash 将启动和退出交互式 Bash shell.