Execute ANT Tasks Remotely
Prerequisites:
- To execute ant targets remotely, we need to have ssh enabled on target machine.
- Need to have jsch-xxxx.jar file placed at <antDir>\lib. Can download this jar file @ https://ant.apache.org/manual/install.html#librarydependencies
Execute ant targets remotely without using CNL:
- Execute ant target present on target machine using following target on source machine:
<target name = "executeAntRemotely">
<sshexec host="${target.host}"
username="${loginUserName}"
password="${loginPassword}"
trust="true"
Command="ant ${targetName} -buildfile ${buildfile} -D<key>=<value> ...."/>
</target>
- Execute batch file present on target machine using following target on source machine:
<target name = "executeBatchRemotely">
<sshexec host="${target.host}"
username="${loginUserName}"
password="${loginPassword}"
trust="true"
Command="<batch file location eg--C:/HudsonRoot/SIQA/ALF_JENKINS/Executables/${batchFileName} >"/>
</target>
- NOTE: Login credentials are of target machine.
Execute ant targets remotely using CNL on source and only Ant on target:(This approach can be used if you dont want to use CNL on target)
Prerequisites On Source Machine:
- CNL checkout is required.
- Install STAF and set system path variable.
- Following parameters may have to be passed for CNL execution:
- ant.target.name = <ant target name>
- ant.xml.file = <full path to build file name ex C:\JobTargets.xml>
- machine.alf.home = <full path to CNL checkout folder>
- WORKSPACE = <workspace>
- machine.name = <CNL.host, host name where CNL is running>
- Rest all remains same, should have following ant target in source machine
<target name = "executeAntRemotely">
<sshexec host="${target.host}"
username="${loginUserName}"
password="${loginPassword}"
trust="true"
Command="ant ${targetName} -buildfile ${buildfile} -D<key>=<value> ...."/>
</target>
Explaination:
- <host>: Target host name.
- <username>: User name for target host.
- <password>: Password for target host.
- <trust>: This trusts all unknown hosts if set to yes or true.
- <Command>: Will execute this command on target host after successful login.