Exception when using sshexec in ant 1.10 - jenkins

I'm trying deploy a PHP application using Ant script. I've put all the necessary jars in the library: ie ant-jsch-1.8.1.jar, jsch-0.1.55.jar
In my script i declare the sshexec and scp as followed:
<path id="jsch.class.path">
<pathelement location="lib/ant-jsch-1.8.1.jar" />
<pathelement location="lib/jsch-0.1.55.jar" />
</path>
<taskdef name="scp" classname="org.apache.tools.ant.taskdefs.optional.ssh.Scp" classpathref="jsch.class.path" />
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jsch.class.path" />
When the build is executed in Jenkins i get these errors event though the location of the public key is correct:
[sshexec] Caught exception: java.io.FileNotFoundException: /home/jenkins/.ssh/id_dsa (No such file or directory)
[sshexec] Caught exception: java.io.FileNotFoundException: /home/jenkins/.ssh/id_dsa (No such file or directory)
[scp] Caught exception: java.io.FileNotFoundException: /home/jenkins/.ssh/id_dsa (No such file or directory)
The weird thing is when i run the build script locally on my machine it works fine.
Any help would be much appreciated.

The issue was that I had a variable that holds the path to the private key, the string probably had an extra space or character and ANT got confused. I replaced variable with the direct path of the private key and it worked. To reuse the variable I copied the path and assigned it to the same variable in run command.

Related

Unable to pass context root to .war application in websphere using wsadmin

I need a little help in updating the context root for my war in my Websphere 8.5 appserver. I have a war file called DefaultApplication.war and during manual deployment through websphere console, iam able to set the context-root. Now i ahve requirment of automating the current flow and i choosed to write ant script to install the war file. Below is the code
<target name="installEAR" depends="uninstallEAR">
<fail unless="wasHome.dir">The property "wasHome.dir" must be specified.
</fail>
<fail unless="appName">The property "appName" must be specified.</fail>
<fail unless="deployEar">The property "deployEar" must be specified.</fail>
<echo message="Deployable EAR File found at: ${deployEar}" />
<wsInstallApp ear="${deployEar}"
options="-appname ${appName} -cell ${was.cell} -node ${was.node} -usedefaultbindings"
wasHome="${wasHome.dir}"
conntype="${connType}"
port="${port}"
host="${hostName}"
user="${userId}"
password="${password}"
failonerror="true" />
</target>
As mentioned in above code, iam setting -usedefaultbindings to use and i have ibm-web-ext.xml file in WEB-INF folder of war file.
Context of ibm-web-ext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee
http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_1.xsd"
version="1.1">
<context-root uri="test"/>
</web-ext>
After deployment my apllication is getting started but unable to access it through /test context path. please help me on this.
Thanks in advance.
You must specify Servlet 3.0 or 3.1 in your web.xml, or ibm-web-ext.xml will not be interpreted. For 2.4, a similar file called ibm-web-ext.xmi is interpreted instead.

Unable to create property file using Ant script

I am trying to create a new Property File with the below snippet of Ant script.
<propertyfile file="${path}/sample.properties">
<entry key="k1" value="v1"/>
</propertyfile>
It tries create the property file and I get the below error
(The system cannot find the path specified). Here the path includes the file name as well. I confirmed the parent folder where the property files needs to be created exists.
I created a build file with your snippet and couldn't see an issue. If the directory specified by the path property doesn't exist an exception is thrown but this seems like the correct behaviour.
I suggest you add some tests to confirm the actual value of the path property. Maybe it doesn't hold the value you expect.
build.xml
<project>
<property name="path" value="./test"/>
<propertyfile file="${path}/sample.properties">
<entry key="k1" value="v1"/>
</propertyfile>
</project>
Test Case 1 - 'test' directory not present - expected result FAIL
$ ls test
ls: cannot access test: No such file or directory
$ ant build.xml
Buildfile: /home/owen/stackoverflow/build.xml
[propertyfile] Creating new property file: /home/owen/stackoverflow/test/sample.properties
BUILD FAILED
/home/owen/stackoverflow/build.xml:3: java.io.FileNotFoundException: /home/owen/stackoverflow/test/sample.properties (No such file or directory)
Total time: 0 seconds
Test Case 2 - 'test' directory now available - expected result SUCCESS
$ mkdir test
$ ant
Buildfile: /home/owen/stackoverflow/build.xml
[propertyfile] Creating new property file: /home/owen/stackoverflow/test/sample.properties
BUILD SUCCESSFUL
Total time: 0 seconds
EDIT: Sorry didn't read the section mentioning that the parent folder exists. For me the given snippet works (in Eclipse). What does your path variable contains and which environment you use exactly ?
All folders specified by your path variable must exist before Ant can create the property file, even before any target is executed.

Cannot run phploc through ANT

I've looked at both these posts.. they don't help:
PHP build for Jenkins failing with 'Cannot run program "phploc"'
Cannot run phploc installed through composer
If I run phploc at a shell prompt, it works just fine. So it must be something with my build.xml file... but I don't know what.
<target name="phploc" description="Measure project size using PHPLOC">
<exec executable="phploc">
<arg path="${basedir}/../src" />
<arg value="--log-csv" />
<arg value="${basedir}/build/logs/phploc.csv" />
</exec>
</target>
This works fine:
C:\projects\project1\build>phploc ../src
phploc 2.0.6 by Sebastian Bergmann.
My folder structure is
c:\projects\project1
build
...
vendor
bin
...
src
tests
c:\projects\project1\build>ant
phploc:
BUILD FAILED
C:\projects\project1\build\build.xml:55: Execute failed: java.io.IOException:
Cannot run program "phploc": CreateProcess error=2, The system cannot find the
file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
UPDATE
C:\>where phploc
INFO: Could not find files for the given pattern(s).
What am I missing?
From chat discussion, it came out to be a PATH related issue. That's exactly what I was thinking it to be.
Setting absolute path of phploc in <exec executable="phploc"> did the trick. It was working on command line from C:\projects\project1\build directory because phploc was in one of its sub-directory (vendor\bin) and this sub-directory was already in the PATH variable.
PATH=C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Calibre2\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files (x86)\IDM Computer Solutions\UltraEdit\;C:\Program Files (x86)\Java;c:\ant\bin;.\vendor\bin
Note: Although providing absolute path worked here but it's a good practice to use relative path so that your project is portable. In this case, you could use basedir as the reference point for all relative paths.

sshexec command setup

I need to run ant script from a local machine which will invoke ant executions on remote machine.
So on the local ant file I have :
<target name="test">
<sshexec host="${host}" username="${user}"
password="${pwd}" trust="yes"
commandResource="(cd F:\execution; ant -f build.xml run)"/>
</target>
On remote machine I have build.xml` which contains
<target name="run">
<mkdir dir ="F:\Testfolder"/>
</target>
When I execute the loca ant script I get the following error :
java.io.FileNotFoundException: (cd F:\execution; ant -f build.xml run)
(The filename, directory name, or volume label syntax is incorrect)
Why am I getting this error?
We deploy a build file named "remote-build.xml" to the path /root/project/remote-build.xml on the remote machine, and then we use
<sshexec host="${host}"
username="${user}"
password="${pwd}"
trust="yes"
command="ant -f /root/project/remote-build.xml the-targets-to-execute" />
to execute the target.
You could create a file in remote machine ( F:\execution\runmanycommands.sh and execute that file . From the site
Run a set of commands from a command resource (file) on a remote
machine using key authentication with no passphrase
The commandResource expects single resource file execute. '(cd F:\execution; ant -f build.xml run)' is not a resource.
(I am not sure your over all goal. Looking at the number questions, I guess you need Continous Integration solution- should check jenkins with many of its plugins )
(BTW, you can all ant directly with ant -f , avoiding the need for cd)

Cannot run program "p4": CreateProcess error=2, The system cannot find the file specified

I'm developing automate deployment script for Coldfusion project.
Tool: cruisecontrol.net, ant script
Source control: perforce
Executing the following ant script from cruisecontrol.net i'm getting this error:
"Cannot run program "p4": CreateProcess error=2, The system cannot find the file specified"
But its working fine from command line:
ant -f deployment.xml
deployment.xml file content:
<!-- Get Latest revision from perforce -->
<echo message="Perforce code base Get Latest revision Started"/>
<p4sync port="${p4.server}"
client="${p4.workspace}"
globalopts="${p4.password}"
user="${p4.username}"
view="${p4.branch}"/>
<echo message="Perforce code base Get Latest revision completed"/>
ccnet.config:
<project name="TestMGDeployment">
<triggers>
<intervalTrigger seconds="300" />
</triggers>
<tasks>
<exec executable="C:\Apache\apache-ant-1.8.1\bin\ant.bat">
<baseDirectory>C:\cruisecontrol\Projects</baseDirectory>
<buildArgs>-f deployment.xml</buildArgs>
</exec>
</tasks>
</project>
Thanks,
Nagarajan
Your CruiseControl.net is probably running under different user account, make sure you have p4 in system PATH or specify the full path to the executable in your p4sync task.
Try running in command line instead of as a service to negate user environment definitions issue.
Check if you have setup the P4PORT environment variable. That should be set to: [your perforce server]:[perforce port].
For e.g., P4PORT=perforce.xyz.com:1666

Resources