Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Bash-git自动部署战争_Java_Git_Bash_Maven_Ubuntu 12.04 - Fatal编程技术网

Java Bash-git自动部署战争

Java Bash-git自动部署战争,java,git,bash,maven,ubuntu-12.04,Java,Git,Bash,Maven,Ubuntu 12.04,我正在尝试制作一个git钩子来自动部署我的war。我创建了一个bash脚本来创建存储库,使用Maven构建,并将war自动部署到jettywebapps文件夹 3) echo "Creating new Maven (Java) repository" echo "Please enter a project name : " read REPO if [ -n $REPO ]; then if [ -d /home/$GITUSER/webapps/$R

我正在尝试制作一个git钩子来自动部署我的war。我创建了一个bash脚本来创建存储库,使用Maven构建,并将war自动部署到jettywebapps文件夹

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://$GITUSER@$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
你能给我一个建议吗?
谢谢

不能将多个文件复制到单个文件中

您的
cp
行是
cp find/path/to/*.war/path/to/file.war
,我不知道以前为什么没有注意到这一点

这有很多问题

find
在那里没有做任何有用的事情(它被视为要复制的文件)

输出目标是一个文件(不是目录)

你需要弄清楚你到底想在那里做什么,并修复复制行


类似于
cp/home/paul/webapps/test/target/*.war/opt/jetty/webapps/test
的东西可能会返回true,如果您没有收到任何输入,请尝试。您需要
[-n“$REPO”]
。一般来说,总是引用你的变量。那一行有什么问题?它不起作用吗?钩子里的那根绳子以后不起作用了吗?什么?在将内容回显到文件之前,没有理由
cat/dev/null>/git/$REPO.git/description
。类似地,在发送内容之前,没有理由触摸/code>touch/git/$REPO.git/hooks/post receive。我粘贴的是我的“外部”脚本的一部分,该脚本创建了钩子,因此问题是命令在repo提供源之前执行。行
echo“cp find/home/$GITUSER/webapps/$repo/target/*.war/opt/jetty/webapps/$repo.war”>>/git/$REPO.git/hooks/post receive
此时未运行
cp
命令。您确实在该行前面的一行末尾有一个奇怪的/杂散的
“\n”
,但这肯定会混淆某些事情。您从脚本中看到的确切输出是什么?(如果将
set-x
添加到该块的顶部会怎么样?)但我希望.war与存储库同名,而我不知道原始文件名。这是我的problem@PaulDumitru如果
/home/paul/webapps/test/target/*.war
只匹配一个文件,那么只需从该行中删除错误的
find
,它就可以工作了。但如果这个glob匹配多个文件,它就会崩溃。谢谢,我会按照你说的去做