2014-12-05 36 views
-1

我試圖做一個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 

你能給我一個建議嗎? 謝謝!

+0

'[-n $ REPO]'將返回true,如果您沒有收到任何輸入,請嘗試。你想要'[-n「$ REPO」]'。一般總是引用你的變量。 – 2014-12-05 14:08:46

+1

該行有什麼問題?它不工作?那鉤子線以後不工作了嗎?什麼? – 2014-12-05 14:09:53

+0

在將內容回顯到文件之前,沒有理由'cat/dev/null>/git/$ REPO.git/description'。同樣沒有理由在發送內容前觸摸/ git/$ REPO.git/hooks/post-receive'。 – 2014-12-05 14:10:59

回答

1

您無法將多個文件複製到單個文件。

您的cp行,我不知道爲什麼我沒有注意到這一點,是cp find /path/to/*.war /path/to/file.war

其中有一些問題。

find沒有做任何有用的事情(它被視爲一個複製文件)。

輸出目標是一個文件(不是目錄)。

您需要弄清楚實際上想要在那裏做什麼並修復該複製行。

或許像cp /home/paul/webapps/test/target/*.war /opt/jetty/webapps/test

+0

但我想讓.war具有與存儲庫相同的名稱,我不知道原始文件名 。這是我的問題 – 2014-12-07 17:15:06

+0

@PaulDumitru如果'/ home/paul/webapps/test/target/*。war'只會匹配一個文件,那麼只要從該行刪除錯誤的'find'就可以了。但是如果該glob匹配多個文件,它將會中斷。 – 2014-12-07 17:16:16

+0

謝謝我會盡力照你說的去做 – 2014-12-07 17:18:00