I want to run my "exec grails" task into my grails project. I set grail path in exec task like
<exec executable="${grails}"
How can I say , that exec should start from my project folder?
From the exec Ant task documentation:
Attribute Description
dir the directory in which the command should be executed.
<exec executable="${grails}" dir="${my.project.dir}">
Related
In other words how to display output of currently executed phing task?
<target name="backup_db">
<mkdir dir="${dir.sql}"/>
<exec command="mysqldump -v -h ${db.host} -u ${db.username} -p${db.password} ${db.name} > ${dir.sql}/${dump.basename}"/>
</target>
This pulls a database dump, as you see I specified -v flag to get verbose output. Command runs successfully however with no output during the dump.
Foo > backup_db:
BUILD FINISHED
Total time: 1 minute 40.81 seconds
The same command called directly in terminal will list each table one by one that's currently being dumped. How to achieve that in phing?
Adding passthru="true" to the exec solved the problem. Now I get the output in real time.
I'm running PostgreSQL 9.2 on Windows 7. I'm trying to run an Ant target using an apply tag with the executable property set to psql from a NetBeans 8.0.2 build file. I have created a pgpass.conf file in the right place with the correct password for the postgres user and I can run psql at a command prompt without having to enter a password. But when I run the Ant target, I get an error message in the output file saying the target failed because no password was supplied. What am I doing wrong? The target looks like this:
<filelist id="create-dbfiles" dir="${root}" files="createdb.sql"/>
<target name="create-db">
<apply executable="psql" addsourcefile="false" output="output.txt">
<arg value="-U postgres" />
<arg value="-w" />
<filelist refid="create-dbfiles"/>
<redirector>
<inputmapper type="glob" from="*" to="${root}\*" />
</redirector>
</apply>
</target>
a_horse_with_no_name got me thinking about the exec tag but trying to run psql directly via an exec tag or an apply tag still threw up errors about a password not being supplied. Then I realised that psql ran smoothly from the cmd prompt. I started playing around with calling cmd.exe and passing a command to the command line, and found a solution:
<filelist id="clean-dbfiles" dir="${root}" files="cleandb.sql"/>
<target name="clean-db">
<apply executable="cmd.exe" addsourcefile="true" >
<filelist refid="clean-dbfiles"/>
<env key="PGPASSWORD" value="rootpassword"></env>
<arg value="/c"></arg>
<arg value="psql -w -U postgres -f " />
<srcfile />
</apply>
</target>
<filelist id="create-dbfiles" dir="${root}" files="createdb.sql"/>
<target name="create-db">
<apply executable="cmd.exe" addsourcefile="true" >
<filelist refid="create-dbfiles"/>
<env key="PGPASSWORD" value="rootpassword"></env>
<arg value="/c"></arg>
<arg value="psql -w -U postgres -f "/>
<srcfile />
</apply>
</target>
Here are the two key targets for creating a build script for a postgres database. Note the following points:
Run cmd.exe not psql directly
Set addsourcefile to true because I want to call neat little self-contained SQL files for each target.
Use apply with a filelist because for my createtables or populate targets I may have a directory of separate SQL files
Give up on hoping to invoke the pgpass.conf file. For some reason Ant in NetBeans can't access it. Resort to the PGPASSWORD environment key and set it to the desired password. This is running locally for development purposes so security isn't an issue.
You need to pass the /c switch to cmd.exe so that you can then pass a command line. I didn't separate the psql command line into separate arguments because I think the complete line is being passed to cmd.exe as a single argument.
addsourcefile is set to true so each file in the filelist is appended to the psql command line just after the -f switch and everything works a treat.
Voilà! What a fuss! I had no similar difficulty with MySql because you can pass the password to the command line directly.
I have used EXEC task to open matlab in build.xml file. I have added timeout in EXEC task for terminate the task after some time. But problem is that, matlab is open and model is also building in matlab but after timeout the exec task not terminate.
<property name="BuildEngine.calc.matlabApp" value="C:\MATLAB\R2010bSP2\bin\matlab.exe"/>
<property name="modelProjectDirectory" value="${basedir}\..\${Config.ModelProject}"/>
<exec executable="${BuildEngine.calc.matlabApp}" dir="${modelProjectDirectory}" timeout="60000">
<arg value="-r"/>
<arg value="OutputResolvedParameters"/>
</exec>
after 1 min EXEC task not terminate and matlab still running.
One thing is sure: you cannot yet set up a timout on an RTC build: the Enhancement 106064 (you need a jazz account to see it) is "triaged".
Regarding the ant exec task, try adding a spawn=true attribute:
If you run Ant as a background process (like ant &) and use the <exec> task with spawn set to false, you must provide explicit input to the forked process or Ant will be suspended because it tries to read from the standard input.
I have a project including a number of vendored javascripts, e.g. jQuery. I'm including these scripts as git submodules. However, for my build process, I need the built script, not the whole repository of that script. So I'm trying to set up a rake task to build each script - preferably using the script's own rakefile - and then copy the built script into my asset directory.
file "app/vendor/scriptname.js" do
# Call the task that builds the script here
sh "cp app/vendor/script-submodule/dist/scriptname.js app/vendor/"
end
desc "Make vendor scripts available for build"
task :vendor => "app/vendor/scriptname.js" do
end
If I use import 'app/vendor/scriptname/Rakefile' in my Rakefile, I should have access to the rake task that builds the script, right? How would I call it? Or should I just use sh "cd app/vendor/script-submodule/ && rake dist" and call it good?
I'm working out a similar problem and it would seem to work just fine by calling the rake task as you normally would. Here's what my example looks like, see if you can get yours to fit.
# Rakefile
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
load 'engines/foo_engine/Rakefile'
MyApp::Application.load_tasks
Then in my submodule's Rakefile:
# engines/foo_engine/Rakefile
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each do |f|
load f
end
And a sample rake task:
# engines/foo_engine/lib/tasks/foo/bar/task.rake
namespace :foo do
namespace :bar do
desc "FooBar task"
task :foo_bar => :environment do
# perform task
end
end
end
Then from the command prompt:
rake foo:bar:task
i´m having a problem with MSBuild and Powershell. There is a PS-script that i want to execute within the MSBuild exec-Task.
The Problem: Running the Script direct from CMD works, but running the script within MSBuild I get an error.
Here the MSBuild script:
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<PathToSvnClient>C:\Program Files (x86)\CollabNet\Subversion Client</PathToSvnClient>
</PropertyGroup>
<ItemGroup>
<!-- set Folder to Svn Repository for svn info command-->
<SvnFolder Include="$(MSBuildProjectDirectory)\.."/>
</ItemGroup>
<Target Name="SvnInfo">
<!-- get SVN Revision and Repository Path -->
<SvnInfo LocalPath="%(SvnFolder.FullPath)" ToolPath="$(PathToSvnClient)">
<Output TaskParameter="Revision" PropertyName="Revision" />
<Output TaskParameter="RepositoryPath" PropertyName="RepositoryPath" />
</SvnInfo>
</Target>
<Target Name="SetProductVersion" DependsOnTargets="SvnInfo">
<Exec Command="powershell -file "Scripts\SetSth.ps1" -PARAM "$(PathToSth)" -SVNID $(Revision) -SVNFOLDER "$(RepositoryPath)"" LogStandardErrorAsError="true" ContinueOnError="false"/>
</Target>
The Command is executed exactly the same way as on CMD, but i get an exception from the Powershell Script for the SVNFOLDER param.
The Command that is executed looks like this:
powershell -file "Scripts\SetSth.ps1" -PARAM "C:\abc\cde" -SVNID 1234
-SVNFOLDER "https://domain/svn/rep/branches/xy%20(Build%2012)"
So from CMD it works, from within MSBuild not. I have no idea why. I hope you got an idea.
What about this approach playing with double and singles quotes:
<Target Name="SetProductVersion" DependsOnTargets="SvnInfo">
<Exec Command="powershell -command "& {Scripts\SetSth.ps1 -PARAM '$(PathToSth)' -SVNID '$(Revision)' -SVNFOLDER '$(RepositoryPath)'}"" LogStandardErrorAsError="true" ContinueOnError="false"/>
</Target>
Double check your paths.
Remember, powershell invoked in this way runs as Msbuild.exe under whatever user is executing the build. To msbuild.exe, a straight call to cmd.exe is going to start in the working directory where msbuild lives.
Assume -file "Scripts\SetSth.ps1" references C:\users\yourusername\Scripts\SetSth.ps1
So for you, calling cmd.exe and running that may work just fine, b/c your working directory is going to match C:\users\yourusername
For msbuild.exe, its likely unable to find that file, as its starting in something like *C:\Windows\Microsoft.NET\Framework\v4.0*
So it's looking for C:\Windows\Microsoft.NET\Framework\v4.0\Scripts\SetSth.ps1
I would try making that file path fully qualified. If that still doesn't work, have cmd.exe dump its results into a property and have msbuild log it. Then you can review the paths.