Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 如果退出代码=0_Shell_Jenkins - Fatal编程技术网

Shell 如果退出代码=0

Shell 如果退出代码=0,shell,jenkins,Shell,Jenkins,我试图在一个shell执行构建步骤中运行多个命令。如果这些命令中的一个存在于0以外的代码中,则生成将立即失败。默认情况下是这样的 我希望生成继续执行此生成步骤中的所有命令,即使给出了一个或多个退出代码0。执行完所有这些命令后,如果退出代码不是0,我希望构建失败 有没有办法只使用控制台命令而不使用(shell)脚本 以下是我正在尝试执行的命令: git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1

我试图在一个shell执行构建步骤中运行多个命令。如果这些命令中的一个存在于0以外的代码中,则生成将立即失败。默认情况下是这样的

我希望生成继续执行此生成步骤中的所有命令,即使给出了一个或多个退出代码0。执行完所有这些命令后,如果退出代码不是0,我希望构建失败

有没有办法只使用控制台命令而不使用(shell)脚本

以下是我正在尝试执行的命令:

git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 -P8 php -l
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 phpcs --standard=PSR2
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 -I file phpmd file text cleancode,codesize,controversial,design,naming,unusedcode
正如您可能知道的,这些是用于php代码分析的,我想在失败之前知道所有错误


提前感谢您的帮助。

使用shell,您可以:

command || true;

为了允许命令失败。

对于shell,您可以执行以下操作:

command || true;

为了允许命令失败。

使用一个变量记录其中一个是否失败,然后检查脚本末尾是否设置了该变量:

FAILURE=0
command1 || FAILURE=1
command2 || FAILURE=1
command3 || FAILURE=1

if [ $FAILURE -eq 1 ]
then
  echo "One or more failures!
  exit 1
fi
因此,在你的情况下:

FAILURE=0
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 -P8 php -l || FAILURE=1
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 phpcs --standard=PSR2 || FAILURE=1
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 -I file phpmd file text cleancode,codesize,controversial,design,naming,unusedcode || FAILURE=1

if [ $FAILURE -eq 1 ]
then
  echo "One or more failures!
  exit 1
fi

使用变量记录其中一个失败的情况,然后检查脚本末尾是否设置了该变量:

FAILURE=0
command1 || FAILURE=1
command2 || FAILURE=1
command3 || FAILURE=1

if [ $FAILURE -eq 1 ]
then
  echo "One or more failures!
  exit 1
fi
因此,在你的情况下:

FAILURE=0
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 -P8 php -l || FAILURE=1
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 phpcs --standard=PSR2 || FAILURE=1
git diff origin/develop --name-only --diff-filter=AM | grep .php | xargs -n1 -I file phpmd file text cleancode,codesize,controversial,design,naming,unusedcode || FAILURE=1

if [ $FAILURE -eq 1 ]
then
  echo "One or more failures!
  exit 1
fi

事实上,即使这些命令中有错误,这也会使构建通过。事实上,即使这些命令中有错误,这也会使构建通过。