我試圖做一個git hook來自動部署我的戰爭。我創建了一個bash腳本來創建存儲庫,與Maven構建和經銷商部署戰爭碼頭的webapps目錄Bash git autodeploy war
3) echo "Creating new Maven (Java) repository"
echo "Please enter a project name : "
read REPO
if [ -n $REPO ]; then
if [ -d /home/$GITUSER/webapps/$REPO ]; then
echo "Destination deployment directory already exists"
else
echo "Creating new repository deployment directory"
mkdir /home/$GITUSER/webapps/$REPO
echo "Creating new repository"
mkdir /git/$REPO.git && cd /git/$REPO.git && git init --bare --shared
echo "Please enter a description for the repository or hit return for none"
read DESC
if [ -n "$DESC" ]; then
cat /dev/null > /git/$REPO.git/description
echo "$DESC" > /git/$REPO.git/description
fi
echo "Creating repository deployment hook"
touch /git/$REPO.git/hooks/post-receive
echo "#!/bin/bash\n" >> /git/$REPO.git/hooks/post-receive
echo "git --work-tree=/home/$GITUSER/webapps/$REPO --git-dir=/git/$REPO.git checkout -f" >> /git/$REPO.git/hooks/post-receive
echo "cd /home/$GITUSER/webapps/$REPO && mvn package" >> /git/$REPO.git/hooks/post-receive "\n"
echo "cp find /home/$GITUSER/webapps/$REPO/target/*.war /opt/jetty/webapps/$REPO.war" >> /git/$REPO.git/hooks/post-receive
chmod +x /git/$REPO.git/hooks/post-receive
echo "Repository created successfuly"
echo "Use git clone ssh://[email protected]$GITDOMAIN:$GITPORT/git/$REPO.git"
echo "Thank you !"
exit
fi
else
echo "Project name cannot be empty"
fi;;
的問題是在這條線在那裏我試圖複製戰爭
echo "cp find /home/$GITUSER/webapps/$REPO/target/*.war /opt/jetty/webapps/$REPO.war" >> /git/$REPO.git/hooks/post-receive
你能給我一個建議嗎? 謝謝!
'[-n $ REPO]'將返回true,如果您沒有收到任何輸入,請嘗試。你想要'[-n「$ REPO」]'。一般總是引用你的變量。 – 2014-12-05 14:08:46
該行有什麼問題?它不工作?那鉤子線以後不工作了嗎?什麼? – 2014-12-05 14:09:53
在將內容回顯到文件之前,沒有理由'cat/dev/null>/git/$ REPO.git/description'。同樣沒有理由在發送內容前觸摸/ git/$ REPO.git/hooks/post-receive'。 – 2014-12-05 14:10:59