Posts Jenkins ant script to loop and stop servers
Post
Cancel

Jenkins ant script to loop and stop servers

  • Script to disable logging
1
2
3
4
<script language="javascript">
    var logger = project.getBuildListeners( ).firstElement( );
    logger.setMessageOutputLevel( 0 );
</script>
  • Call target from pom.xml
1
2
3
4
5
6
7
<configuration>
    <target>
        <ant antfile="${basedir}/build.xml">
            <target name="deploy" />
        </ant>
    </target>
</configuration>
  • Setup profile and add servers for that environment
1
2
3
4
5
6
7
8
9
<profile>
    <id>dev</id>
    <properties>
        <classifier.type>DEV</classifier.type>
        <server1.hostname>server1</server1.hostname>
        <server2.hostname>server2</server2.hostname>
        <server3.hostname>server3</server3.hostname>
    </properties>
</profile>
  • Ant Loop command
1
2
<for list="${sorted.hostnames}" param="hostname">
</for>
  • Ant ssh and execute commands on remote
1
2
3
4
5
6
7
<sshexec 
    host="${node}"
    username="server" 
    password="${server.password}"
    command=". .bash_profile;
            server stop;"
    trust="true" />

Source

This post is licensed under CC BY 4.0 by the author.