我正在尝试为一个C项目的CI设置一个Azure DevOps构建管道,这个项目是使用gnu make构建的,最终运行gcc进行编译和链接。
虽然我不确定要将哪个任务添加到管道中以构建Makefile项目,但我尝试了一个简单的命令行脚本任务,它只是在适当的目录中执行'make‘。
问题在于检测构建是否失败。在命令行脚本任务的"Advanced“部分下,只有"Fail on Standard Error”选项。描述说,如果向stderr写入任何内容,任务将失败。
因此,如果出现编译或链接错误,任务确实会失败,这是预期的行为。然而,gcc也将所有编译警告写到stderr,这也会导致任务失败,这不是我们想要的。
不检查“在标准错误上失败”会导致构建被标记为成功,而不管有多少真正的错误。
当同样的构建作为Jenkins作业的一部分运行时,它不知何故能够正确地解释gcc/make输出,并且只有在报告了实际错误的情况下才会使构建失败。有没有办法在Azure管道中复制相同的行为?没有修复所有警告或重新设计构建过程以不向stderr写入任何内容,然后使用一些其他方法来测试构建是否成功?
发布于 2020-02-06 17:28:53
命令行脚本任务只是将提供的脚本作为shell脚本运行,并检查其退出代码(非零表示错误)。问题是,脚本的退出代码是最后一条语句的退出代码,默认情况下(除非指定了-e选项),shell将不考虑错误而继续运行,即:
失败的命令
步骤内容:
make -f nonexisting.mk结果:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/bc2da066-dd8a-432d-b15f-b9c2bf7a8e1f.sh
make: nonexisting.mk: No such file or directory
make: *** No rule to make target 'nonexisting.mk'. Stop.
##[error]Bash exited with code '2'.
Finishing: Command Line Scriptmake命令无法返回退出代码%2,并且任务被标记为失败。已跳过下一个任务。
失败的命令被下一条语句覆盖
步骤内容:
make -f nonexisting.mk
echo Do whatever else结果:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/0b2ceea2-2821-4866-83c7-5d37a832ffe5.sh
make: nonexisting.mk: No such file or directory
make: *** No rule to make target 'nonexisting.mk'. Stop.
Do whatever else
Finishing: Command Line Scriptmake命令失败,但外壳程序继续执行成功的下一条语句(echo),因此退出代码为0,任务未检测到错误,管道成功执行。
允许shell在出现错误时停止
步骤内容:
set -e
make -f nonexisting.mk
echo Do whatever else结果:
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/7f6644d3-408c-4b5b-b4d3-1f544e8a80ec.sh
make: nonexisting.mk: No such file or directory
make: *** No rule to make target 'nonexisting.mk'. Stop.
##[error]Bash exited with code '2'.
Finishing: Command Line Scriptshell可以在遇到任何错误时退出;当make命令失败时,脚本将终止,echo命令不会执行,退出代码是失败命令的退出代码。任务再次检测到这一点,流水线被终止。
顺便说一句。这是Jenkins运行shell脚本的标准方式,默认情况下传递-e,这样它就可以在Jenkins上运行,而无需显式执行任何操作。
您可能需要检查任务脚本中是否有覆盖make退出代码的命令。脚本中的set -e可能会做到这一点,除非您希望在脚本中包含更复杂的逻辑。
https://stackoverflow.com/questions/60086826
复制相似问题