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>
Related
I have tasks running in Ant, which I'm quite new to, as part of a CI chain of build events. I used a tutorial to create the file for testing/linting/etc a PHP application.
The first important directives in the build.xml are:
<property name="phpmd" value="phpmd"/>
<property name="phpunit" value="phpunit"/>
This works fine as is, assuming that phpmd/phpunit are on the path, and using phpunit as a further example, is run under the following target:
<target name="phpunit" unless="phpunit.done" depends="prepare" description="Run unit tests with PHPUnit">
<exec executable="${phpunit}" resultproperty="result.phpunit" taskname="phpunit">
<arg value="--configuration"/>
<arg path="${basedir}/phpunit.xml"/>
</exec>
<property name="phpunit.done" value="true"/>
</target>
All this works well as is- but I want to use docker from now on, which I had hoped would simply mean changing <property name="phpunit" value="phpunit"/> to <property name="phpunit" value="docker-compose run php phpunit"/>, but this instead gives me the following error:
Execute failed: java.io.IOException: Cannot run program "docker-compose run -w /var/www/src php phpunit" (in directory "/var/lib/jenkins/jobs/Blah blah blah/workspace/src"): error=2, No such file or directory
I know that you would usually add additional <arg/> nodes to targets- but is it not possible at all to provide the full command with inline arguments on the initial <property>?
Ant is obviously complaining because, along with those inline arguments, that executable doesn't exist. Will I have to use arg nodes and update every single target?
Using docker-compose alone works fine, but I need the args for the correct container and working directory to be used- preferably inline, otherwise I have to insert many arg nodes.
In the end I just created a property for phpunit arguments and then added it by using the <args line="${phpunitArgs}">.
Definitely not ideal, but at least it does what it is supposed to. I certainly prefer using Gulp! XML feels like a bad choice for a build system.
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.
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'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