I'm trying to create a batch file that automates an annoying build process. The key part that's tripping me up is when a command starts a process that takes over input from the keyboard.
Basically, I run something along the lines of ant -f build-rmi.xml rmiregistry, which builds and runs the rmiregistry. After this is completed i need to run another build, but I can't figure out how to launch another command after the ant build is finished executing
I don't have write access to any of the ant files.
Create a new ANT build script run-both.xml
Add an Import in run-both.xml to get the original script.
Create a new target in run-both.xml, say "runbatch".Use ANT exec task to call the DOS command from this target
<project name="run-both" default="runbatch">
<import file="${path_to_rmi}/build-rmi.xml"/>
<target name="runbatch" depends="rmiregistry">
<exec executable="cmd">
<arg value="/c"/>
<arg value="echo hello Matt"/>
</exec>
</target>
</project>
On the command prompt
ant -f run-both.xml
use command call , the batch script file will not stop after run ant command
call ant
Related
I'm trying to create an ANT script which amongst other things will configure IIS.
To do this, trying to harness the appcmd tool. However getting a strange error. The appcmd command runs fine outside of the ant script, but fails within.
I'm using the exec task to kick it all off :
<exec dir="C:\\Windows\\System32\\inetsrv\\"
executable="C:\\Windows\\System32\\inetsrv\\appcmd.exe" output="d:\out.txt">
<arg value="appcmd set config /section:isapiCgiRestriction /+"
[path='${appian_home}\\jakarta\\ISAPI\\isapi_redirect.dll',
description='Jakarta',allowed='True']"" />
</exec>
The output trapped via ANT is :
Object 'APPCMD SET CONFIG /SECTION:ISAPICGIRESTRICTION /+?
[PATH='D:\PTMP2\APPIAN17\\JAKARTA\\ISAPI\\ISAPI_REDIRECT.DLL',
DESCRIPTION='JAKARTA',ALLOWED='TRUE']' is not supported.
Run 'appcmd.exe /?' to display supported objects.
However when I run
If I c&p that command to the dos prompt it will happily run :
C:\Windows\System32\inetsrv>appcmd set config /section:isapiCgiRestriction
/+"[path='d:\ptmp2\appian17\\jakarta5\\ISAPI\\isapi_redirect.dll',descripti
on='Jakarta',allowed='True']"
Applied configuration changes to section
"system.webServer/security/isapiCgiRestriction" for
"MACHINE/WEBROOT/APPHOST" at configuration commit path "M
ACHINE/WEBROOT/APPHOST"
Needs to escaped single quote as well.
Also changed path separate to /
Use below:
<exec executable="cmd.exe" dir="C:/Windows/System32/inetsrv" failonerror="true">
<arg line="/c appcmd set config /section:isapiCgiRestriction /+"[path='${appian_home}/jakarta/ISAPI/isapi_redirect.dll',description='Jakarta',allowed='True']""/>
</exec>
I have the following in my Phing build file:
<target name="fixModifiedTime">
<echo msg="Fixing file modified time" />
<exec executable="python" >
<arg value="c:\scm\scripts\git-restore-mtime.py" />
<arg value="-v" />
</exec>
</target>
This is causing the following error in my Jenkins output:
[exec] Executing command: python c:\scm\scripts\git-restore-mtime.py -v 2>&1
[exec] 'python' is not recognized as an internal or external command,
[exec] operable program or batch file.
I am able to execute the same command from the Jenkins workspace directory and it works perfectly. The Python directory is added to my environment variables and the script has the right permissions.
I have also tried adding the script to my repository and running it from within the build environment but have the same error.
Any thoughts please?
I suggest the following:
Try creating Windows batch build step in your Jenkins and put the command in it. See if it runs
It's obvious your Jenkins environment is not the same is your console. See what's missing in Jenkins
Add the python home and path in the Jenkins configuration
I hope this helps
I'd like to use ant to compile several of my handlebars templates.
The command I'd like to run is:
handlebars templates -f templates/hbs.js
My ant file has the following:
<exec executable="handlebars">
<arg value="${src.templates.dir}"/>
<arg value="-f"/>
<arg value="${src.templates.dir}/hbs2.js"/>
</exec>
I get a BUILD FAILED error where it reads
Execute failed: java.io.IOException: Cannont run program "handlebars": CreateProcess error-2, the system cannot find the file specified.
I've also tried
<exec executable="handlebars.exe">
with the same result. Handlebars works because I can run the command from a terminal window from the same location as my ant build files.
I've got handlebars installed through node.js. I know I can probably get it to work by using node to build my project, but I'm hoping I don't have to convert my other ant tasks.
See the windows section of the "exec" task:
http://ant.apache.org/manual/Tasks/exec.html
I have a STAF job which kicks off an Ant script, all run under a functional ID. The ant script does basic 'init' tasks which work fine, and then hangs on one of the following tasks: delete, mkdir, or junit, depending on how much muddling I do in the file system.
<target name="run.nightly.tests" depends="init">
<delete dir="/path/results/latestDate" />
<mkdir dir="/path/results/latestDate" />
<chmod perm="777" dir="/path/results/latestDate" />
<junit printsummary="on" fork="no">
<!-- typical classpath/tests setup snipped -->
</junit>
</target>
I am able to sudo to this functional ID and run the corresponding commands from a shell just fine (ex: rm -rf /path/results/latestDate). Clearly something is different about running in the Ant environment, under the functional id. (In fact, I can run the script just fine with my own id)
/path/results has 777 permissions before my script runs, and when /path/results/latestDate exists it is owned by the same functional id w/ 777 permissions.
STAF launches this script:
export ANT_HOME=/opt/apache-ant-1.8.2
#This entire directory tree and jar files are world r+x
LIB_DIR=/home/afreed/automation/dependencies/mail
ant -debug -verbose -buildfile nightlyTest.xml -lib ${LIB_DIR}/mail.jar:${LIB_DIR}/activation.jar
I would understand if Ant would fail on any of these tasks with a permissions error but I cannot understand why it would hang.
I would like help either a) determining why there is a hang or b) how to convert the hang to a hard failure
Solved, the Ant script was hanging on an exec command that was waiting for input from STDIN. (Execution had continued past that point because it was launched with 'spawn' attribute.) When I removed this 'exec' task from my 'init' target, the Ant script ran as expected.
<!-- hanging task in init-->
<exec executable="blah.sh" spawn="true">
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)