繁体   English   中英

Jenkins中的Shell脚本

[英]Shell Script in Jenkins

我正在詹金斯管道步骤中运行shell脚本。 脚本正在执行Maven构建和其他一些工作。 如果maven构建失败,我希望管道失败。 我不确定该怎么做。

这是我的剧本

#!/usr/bin/env bash
echo "Acceptance Test"
cd .. && cd $PWD/transactions-ui
npm run acceptance-start && cd .. &&  cd $PWD/transactions-test/ && mvn verify -Dserenity.reports=email -Dwebdriver.driver=chrome  -Dwebdriver.provided.mydriver=starter.util.RemoteChromeDriver ; cd .. ;  cd $PWD/transactions-ui/ ; npm run acceptance-stop
echo "Test completed"

以下是我的詹金斯档案

dir("${workspace}/transactions-test")
                {
                    sh "${workspace}/transactions-test/run.sh"
                }

这取决于您如何定义失败。 如果您的run.sh脚本的退出代码不同于0,则构建将失败。

如果有任何命令返回非零状态,则在bash中添加set -e退出

#!/usr/bin/env bash
set -e
echo "Acceptance Test"
...

Bash set命令供参考。

如果set -e对您不起作用,则可以按以下方法检查关键的cmd结果:

#!/usr/bin/env bash
echo "Acceptance Test"
cd ..
cd $PWD/transactions-ui
npm run acceptance-start

if [[ $? -ne 0 ]]; then
  echo "npm run acceptance-start failed"
  exit 1
fi

cd .. 
cd $PWD/transactions-test/
mvn verify \
  -Dserenity.reports=email \
  -Dwebdriver.driver=chrome \
  -Dwebdriver.provided.mydriver=starter.util.RemoteChromeDriver

if [[ $? -ne 0 ]]; then
  echo "mvn verify failed"
  exit 1
fi

cd .. 
cd $PWD/transactions-ui/
npm run acceptance-stop

if [[ $? -ne 0 ]]; then
  echo "npm run acceptance-stop failed"
  exit 1
fi

echo "Test completed"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM