我有一个用于安装 Jenkins 插件的简单 shell 脚本:
installPlugin() {
{...}
}
for f in ${plugin_dir}/*.hpi ; do
#without optionals
deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | tr '\n' ' ' )
for plugin in $deps; do
installPlugin "$plugin" 1 && changed=1
done
done
我像这样从 Dockerfile 调用这个脚本:
RUN JENKINS_HOME=$JENKINS_HOME \
http_proxy=$http_proxy \
https_proxy=$https_proxy \
$JENKINS_HOME/install_plugin.sh \
ace-editor:1.1 \
即使 unzip 例程未安装在 Dockerfile 中,当我运行 docker build
时,即使缺少 unzip,输出仍然是成功的。如果以下步骤失败,我希望构建失败:
deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | tr '\n' ' ' )
非常感谢任何帮助!
乐
脚本输出如下:
/var/jenkins/install_plugin.sh: line 62: unzip: command not found
deps=
但是,即使该脚本失败,docker build 也不会失败:
Successfully built 54f5a5ec567d
最佳答案
我最后做了这样一张空支票:
for f in ${plugin_dir}/*.hpi ; do
manifestMf=$(unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r')
if [ $manifestMf=="" ]; then
echo "Invalid META-INF/MANIFEST inside $f"
exit 1
fi;
#without optionals
deps=$(echo $manifestMf | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | grep -v "resolution:=optional" | tr '\n' ' ' )
# with optionals
#deps=$( unzip -p ${f} META-INF/MANIFEST.MF | tr -d '\r' | sed -e ':a;N;$!ba;s/\n //g' | grep -e "^Plugin-Dependencies: " | awk '{ print $2 }' | tr ',' '\n' | tr '\n' ' ' )
for plugin in $deps; do
installPlugin "$plugin" 1 && changed=1
done
done
done
关于linux - 调用未安装的例程时 Shell 脚本不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56000655/