Running ant from jenkins - jenkins

I am trying to deploy my zip file from local machine to remote machine, i am using jenkins with ant. the problem is build gets success but 0 files has been sent to remote machine using ftp.
my build.xml file as below
<project name="test" default="test">
<target name="test">
<zip destfile="htmlfiles.zip">
<fileset dir=".">
<include name="**/*.php"/>
</fileset>
</zip>
<ftp server="192.168.0.66"
userid="admin"
password="admin">
<fileset dir="C:\Users\ADMIN\Desktop\ftp">
<include name="*"/>
</fileset>
</ftp>
</target>
</project>
and following my result of jenkins
test:
[zip] Building zip: C:\Users\ADMIN\.jenkins\workspace\test\htmlfiles.zip
[ftp] sending files
[ftp] 0 files sent
BUILD SUCCESSFUL
Total time: 0 seconds
Finished: SUCCESS
anyone help me out that why it is happening?

Try this and let me know if its works for you.
<project name="test" default="test">
<target name="test">
<property name="distdir" value="C:\Users\ADMIN\Desktop\ftp"/>
<zip destfile="${distdir}/htmlfiles.zip">
<fileset dir=".">
<include name="**/*.php"/>
</fileset>
</zip>
<ftp server="192.168.0.66"
userid="admin"
password="admin">
<fileset dir="C:\Users\ADMIN\Desktop\ftp">
<include name="*"/>
</fileset>
</ftp>
</target>
</project>
As i can see from logs that your .zip file is created at C:\Users\ADMIN\.jenkins\workspace\test\htmlfiles.zip but in ftp tag you have specified the location "C:\Users\ADMIN\Desktop\ftp". fileset in ftp folder doesn't specify the destination directory. The file will be put in default folder for ftp user(here which is admin)

Related

Transfer files from local machine(i.e) windows to remote machine(Ubuntu) using ANT script through scp

I wrote this simple script to transfer files from my machine to remote machine. Here I included the jars of ant.
<?xml version="1.0" encoding="UTF-8"?>
<project name="File_Transfer_using_ANT" default=".">
<property name="lib" location="lib" />
<path id="project.classpath">
<fileset dir="${lib}">
<include name="*.jar" />
</fileset>
</path>
<target name="copy">
<classpath refid="project.classpath" />
<scp todir="username:password#ip:path/">
<fileset dir="source path">
<include name="**/*.txt" />
</fileset>
</scp>
</target>
</project>
Error:
java.lang.NoSuchMethodError: com.jcraft.jsch.Session.setConfig(Ljava/lang/String;Ljava/lang/String;)V
at org.apache.tools.ant.taskdefs.optional.ssh.SSHBase.openSession(SSHBase.java:221)
I also Added jar file required into ant lib path. I don't know where I did wrong.

Execute task before directory is loaded

I have a build.xml with several <taskdef>s and <target>s. Furthermore, a <property> and a <path> are set:
<property name="foo" location="/some/path/elsewhere" />
<path id="foo.path">
<fileset dir="${foo}">
<include name="*.jar" />
<include name="**/*.jar" />
</fileset>
</path>
One <target> trys to <move> (rename) directories which are under foo.path. This doesn't work because Ant already loaded that stuff, which blocks <move> on system level.
Is there a way to execute some sort of task before the directory in <property> and/or <path> is loaded?
EDIT: <move> task looks as follows:
<target name="moveDirs" if="some.condition">
<move todir="/some/path_old">
<fileset dir="/some/path"/>
</move>
<move todir="/some/path">
<fileset dir="/some/path_new"/>
</move>
</target>
Basically, I'm trying to rename /some/path to /some/path_old and /some/path_new to /some/path. As mentioned before, foo.path points to a folder under /some/path.

Even if I close target tag in ant also showing error. How can i fix target closing error in ant?

I am using ant 1.7.1 version.my build.xml file is `
<target name ="target1" >
<property name="javasrc" value="/Ant/java" />
<property name= "javaclassdest" value="/Ant/javaclass"/>
<javac srcdir="${javasrc}" destdir="${javaclassdest}"/>
<echo> creating jar</echo>
<property name="jardest" value="/Ant/jar"/>
<property name="jclass-src" value="/Ant/javaclass"/>
<fileset dir="${javaclassdeest}" casesensitive="yes"/>
<include name="**/*.class"/>
<exclude name="**/*.png"/>
</fileset>
<jar destfile="${jardest}/app.jar" basedir="${jclass-src}"/>
</target>
</project>
`
In build.xml file proper closed target </target> tag is there. but when I run with ant command it showing below error
`[root#ram Ant]# ant
Buildfile: build.xml
BUILD FAILED
/Ant/build.xml:18: The element type "target" must be terminated by the matching end-tag "</target>".
Total time: 0 seconds
`
How can I fix this problem?
Problem is in your fileset call: it ends with a trailing slash, remove it and it should work :
<fileset dir="${javaclassdeest}" casesensitive="yes">
<include name="**/*.class"/>
<exclude name="**/*.png"/>
</fileset>

how to excludes and include task in ant script

I want to copy only specific jar file using ant script. It is very easy task but i am not able to do this. I have written the below ant script for this task. I want to excludes all jar file except aopalliance-.jar file. But when i run this script it excludes all the jar file. can someone correct this script .
<?xml version="1.0" encoding="UTF-8"?>
<project default="mvcexample" name="MVCExample" basedir=".">
<property name="web.dir" value="WebContent" />
<property name="webinf.dir" value="WebContent/WEB-INF" />
<property name="lib.dir" value="WebContent/WEB-INF/lib" />
<property name="lib2.dir" value="WebContent/WEB-INF/lib2" />
<target name="copyjar">
<copy todir="${lib2.dir}">
<fileset dir="${lib.dir}" excludes="**/*.jar">
<include name="${lib.dir}/aopalliance-.jar"></include>
</fileset>
</copy>
</target>
</project>
Here's what you need to do:
<target name="copyjar">
<copy todir="${lib2.dir}">
<fileset dir="${lib.dir}">
<!-- <include name="${lib.dir}/aopalliance-.jar"/> -->
<include name="aopalliance-.jar"/> <!-- Don't put the dir name! -->
</fileset>
</copy>
</target>
When you specify a directory, you merely specify the name pattern under that directory. What you were asking for was the jar ${lib.dir}/${lib.dir}/aopalliance-.jar. By the way, is there suppose to be a version number in there somewhere? Like aopalliance-3.4.jar? If so, you need <include name="aopalliance-*.jar"/>.
Also notice that if I used <include .../> instead of <include...></include>.

Using Ant for S3 Uploading

I tried to implement the awstasks Class for uploading files via an ant script to an S3 bucket.
Downloaded all dependencies and used the following code:
<taskdef name="S3Upload" classname="dak.ant.taskdefs.S3Upload">
<classpath refid="classpath.compile"/>
</taskdef>
<target name="final2S3">
<basename property="customer.id" file="${basedir}"/>
<basename property="customer.name" file="${basedir.parent.parent}"/>
<basename property="customer.campaign" file="${basedir.parent}"/>
<basename property="customer.final" file="${basedir.parent}\_final\${customer.id}\"/>
<S3Upload verbose="true"
accessId="${aws.accessId}"
secretKey="${aws.secretKey}"
bucket="${aws.bucket}\${customer.id}"
publicRead="true">
<fileset dir="${customer.final}">
<include name="**/*.json"/>
<include name="**/*.swf"/>
</fileset>
</S3Upload>
</target>
I get the following error:
Reference classpath.compile not found.
I tried to set the property classpath.compile to the lib folder in the Ant home but nothing changes.

Resources