Jenkins ant script to ssh and restart remote application
Jenkins ant script to ssh and restart remote application
Part of the same deployment pipeline as the stop script — SSH into a remote server and restart the application. The sshexec Ant task handles the connection and command execution. The profile setup means the same script works across environments by just changing the active Maven profile.
- 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 list server for that environment
1
2
3
4
5
6
7
<profile>
<id>dev</id>
<properties>
<classifier.type>DEV</classifier.type>
<server.hostname>localhost</server.hostname>
</properties>
</profile>
- 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.sh restart;"
trust="true" />
Source
This post is licensed under
CC BY 4.0
by the author.