maven - Jenkins + maven cargo + 2 tomcats

标签 maven tomcat jenkins cargo

我正在使用 Jenkins 使用 Maven 构建 war 文件,我需要将它同时部署到 2 个正在运行的 tomcat。我在 pom.xml 中写了两个配置文件(针对每个 tomcat),但是当我运行时

cargo:deploy -Pprofile1,profile2

它仅部署到 profile2。所以我需要运行命令 2 次:

cargo:deploy -Pprofile1 
cargo:deploy -Pprofile2

这就是我的 pom.xml 的样子:

        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.4.8</version>
            <configuration>
                <container>
                    <containerId>tomcat7x</containerId>
                    <type>remote</type>
                </container>
                <configuration>
                    <type>runtime</type>
                    <properties>
                        <cargo.remote.uri>${cargo.manager.url}</cargo.remote.uri> 
                        <cargo.remote.username>${cargo.username}</cargo.remote.username>
                        <cargo.remote.password>${cargo.password}</cargo.remote.password>
                    </properties> 
                </configuration>
                <deployables>
                    <deployable>
                        <groupId>com.softserveinc</groupId>
                        <artifactId>oms</artifactId>
                        <!-- <version>1.0.0-BUILD-SNAPSHOT</version> -->
                        <type>war</type>
                    </deployable>
                </deployables>
            </configuration>
        </plugin>       
    </plugins>
</build>
<profiles>
    <profile>
        <id>profile1</id>
            <properties>
            <cargo.manager.url>http://<here shuold be ip addres>/manager/text</cargo.manager.url>
            <cargo.username>admin</cargo.username>
            <cargo.password>admin</cargo.password>
       </properties>
    </profile>
    <profile>
        <id>profile2</id>
        <properties>
            <cargo.manager.url>http://<here shuold be ip addres>/manager/text</cargo.manager.url>
            <cargo.username>admin</cargo.username>
            <cargo.password>admin</cargo.password>
        </properties>
    </profile>
</profiles>

但我需要通过 1 个命令为 2 个 tomcat 执行此操作?有人知道怎么做吗?

最佳答案

编写调用 Cargo 部署命令的脚本。

这是 Jinja 模板,它从 ansible list 文件动态创建:

#!/bin/sh
function deploy
{
echo "Changing working directory to om"
cd /home/install/some

{% for host in groups['app'] %}
echo "Deploying application to {{host}} server"
{{installation_folder}}/maven/bin/mvn cargo:redeploy -P{{host}}
{% endfor %}
}

echo "Downloading the latest version of oms.war"
wget "http://{{groups['CS'][0]}}:8081/nexus/service/local/artifact/maven/redirect?r=snapshots&g=com.softserveinc&a=oms&v=1.0.0-BUILD-SNAPSHOT&p=war" -O /tmp/some.war

deploy

echo "Removing some.war"
rm -rf /tmp/oms.war

关于maven - Jenkins + maven cargo + 2 tomcats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24974049/

相关文章:

java - Maven pom.xml 问题(缺少项目构建错误 "version")

jenkins - Jenkins 保留构建和工件的默认行为

java - Jenkins 不可读的 POM

tomcat - Jersey Servlet - 设置根 uri 内容的最佳方式?

python - 如何在 Jenkins 中创建一个通用函数来执行 python 脚本

maven - 高级Docker和Dockerfile的卷/写出理解

java - 在 Maven 构建中执行其他任务

maven - 查找 Maven 依赖项的顺序是什么?

java - 使用 getResourceAsStream 时发现错误 "Method May Fail to Close Stream"

java - Ant Tomcat 7 重新加载 FileNotFoundException