maventomcatjenkinscargo

Jenkins + maven Cargo + 2 tomcats


I am building war file by Jenkins with maven and i need to deploy it to the 2 running tomcats at the same time. I wrote two profiles(for each tomcat) in the pom.xml, but when i run

cargo:deploy -Pprofile1,profile2

its deploying only to profile2. So i need to run command 2 times:

cargo:deploy -Pprofile1 
cargo:deploy -Pprofile2

thats how my pom.xml looks:

        <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>

but i need to do it for 2 tomcats by 1 command? someone know how to do it?


Solution

  • Wrote script which invoked Cargo deploy command.

    Here is Jinja template, which creates dynamically from ansible inventory file:

    #!/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