我试图在bash命令行中创建一个if语句,而不是脚本,但是可以在命令行中输入一个语句而不返回,因为我必须通过groovy命令行调用来运行这个脚本。
if [cat $(find ./ -name userId.txt) == "517980"]; then cat $(find ./ -name userId.txt); fi
Jenkins groovy脚本看起来像这样
node("puppet-$ENVIRONMENT") {
sh "/opt/puppet/bin/puppet module uninstall ${module} || echo 'NOT INSTALLED!'"
sh "pwd"
sh "rm -rf *"
//unarchive the tar in the remote file system and install it
unarchive mapping: ['*.*': './']
sh 'if [cat $(find ./ -name userId.txt) == "517980"]; then echo "it works"; fi'
sh "ls -alrt"
sh '/opt/puppet/bin/puppet module install --force $(find ./ -name *.tar.gz)'
}
答案 0 :(得分:2)
file=$(find ./ -name userId.txt) && [ -n "$file" ] && { contents=$(cat "$file"); [ "$contents" == "517980" ] && echo "$contents"; }
find
或cat
[
实际上是命令而不仅仅是语法:它需要一个空格来将其与参数分开$()
来电cat