Azure DevOps bash 脚本在 PATH 上看不到二进制文件
Azure DevOps bash script not seeing binaries on PATH
我正在尝试在我的构建管道中执行一个 Bash 脚本,该脚本是 运行 在自托管代理上。我遇到的错误是:
##[section]Starting: Bash
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.148.2
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613738)
==============================================================================
Generating script.
[command]C:\WINDOWS\system32\bash.exe --noprofile --norc -c pwd
/mnt/c/agent/_work/1/s/utilities/Uncrustify
Formatted command: . '/mnt/c/agent/_work/1/s/utilities/Uncrustify/check.sh'
[command]C:\WINDOWS\system32\bash.exe --noprofile --norc -c pwd
/mnt/c/agent/_work/_temp
========================== Starting Command Output ===========================
[command]C:\WINDOWS\system32\bash.exe --noprofile --norc /mnt/c/agent/_work/_temp/146cb6ce-a7e9-48f6-b4f9-6cde2bf22685.sh
/mnt/c/agent/_work/1/s/utilities/Uncrustify/check.sh: line 27: uncrustify: command not found
##[error]Bash exited with code '127'.
##[error]Bash wrote one or more lines to the standard error stream.
##[section]Finishing: Bash
check.sh
脚本简单地 运行s uncrustify:
#!/bin/bash
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT="[=12=]"
# Absolute path this script is in, e.g. /home/user/bin/
SCRIPTPATH="$(dirname -- "$SCRIPT")"
# Relative path from this script to the top level of this repo.
GITREPO="$SCRIPTPATH/../.."
uncrustify --check -c "$GITREPO/.uncrustify.cfg" \
$(find "$GITREPO" -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx")
azure-pipelines.yml
中的bash任务是:
- task: Bash@3
inputs:
filePath: 'utilities/Uncrustify/check.sh'
displayName: 'Verify coding standard compliance'
failOnStderr: true
我已经验证 uncrustify.exe
存在于 PATH 中,恰好在 /mnt/c/ProgramData/chocolatey/bin
中。我不确定我做错了什么。我是否需要做一些特殊的事情来允许 bash 脚本调用可能在 PATH 上的其他可执行文件?
经过大约一个小时的反复试验,解决方法是在 shell 脚本中明确指定扩展名。
uncrustify --check -c "$GITREPO/.uncrustify.cfg" \
$(find "$GITREPO" -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx")
变成了:
uncrustify.exe --check -c "$GITREPO/.uncrustify.cfg" \
$(find "$GITREPO" -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx")
这种小事。在我的任何设置上手动实际执行时,这不是问题。
我正在尝试在我的构建管道中执行一个 Bash 脚本,该脚本是 运行 在自托管代理上。我遇到的错误是:
##[section]Starting: Bash
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.148.2
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613738)
==============================================================================
Generating script.
[command]C:\WINDOWS\system32\bash.exe --noprofile --norc -c pwd
/mnt/c/agent/_work/1/s/utilities/Uncrustify
Formatted command: . '/mnt/c/agent/_work/1/s/utilities/Uncrustify/check.sh'
[command]C:\WINDOWS\system32\bash.exe --noprofile --norc -c pwd
/mnt/c/agent/_work/_temp
========================== Starting Command Output ===========================
[command]C:\WINDOWS\system32\bash.exe --noprofile --norc /mnt/c/agent/_work/_temp/146cb6ce-a7e9-48f6-b4f9-6cde2bf22685.sh
/mnt/c/agent/_work/1/s/utilities/Uncrustify/check.sh: line 27: uncrustify: command not found
##[error]Bash exited with code '127'.
##[error]Bash wrote one or more lines to the standard error stream.
##[section]Finishing: Bash
check.sh
脚本简单地 运行s uncrustify:
#!/bin/bash
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT="[=12=]"
# Absolute path this script is in, e.g. /home/user/bin/
SCRIPTPATH="$(dirname -- "$SCRIPT")"
# Relative path from this script to the top level of this repo.
GITREPO="$SCRIPTPATH/../.."
uncrustify --check -c "$GITREPO/.uncrustify.cfg" \
$(find "$GITREPO" -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx")
azure-pipelines.yml
中的bash任务是:
- task: Bash@3
inputs:
filePath: 'utilities/Uncrustify/check.sh'
displayName: 'Verify coding standard compliance'
failOnStderr: true
我已经验证 uncrustify.exe
存在于 PATH 中,恰好在 /mnt/c/ProgramData/chocolatey/bin
中。我不确定我做错了什么。我是否需要做一些特殊的事情来允许 bash 脚本调用可能在 PATH 上的其他可执行文件?
经过大约一个小时的反复试验,解决方法是在 shell 脚本中明确指定扩展名。
uncrustify --check -c "$GITREPO/.uncrustify.cfg" \
$(find "$GITREPO" -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx")
变成了:
uncrustify.exe --check -c "$GITREPO/.uncrustify.cfg" \
$(find "$GITREPO" -name "*.c" -o -name "*.cpp" -o -name "*.cxx" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx")
这种小事。在我的任何设置上手动实际执行时,这不是问题。