I am using cruisecontrol and ant to build some legacy executables that also depend on a shell profile to setup env vars properly. Is there a way to exec this profile using ant in the current process so the makefiles ant calls get the env vars correctly?
Another solution would be if there is a way to add the profile sourcing to the sub make files I'm calling.
Edit: I guess I wasn't clear in my question. I know what env varibles need to be passed to make using the exec/env tasks. However, I don't know how to have ant grab the values from a shell profile that is usually sourced via: . /usr/local/profile/foo.profile
I figured out how to do it based off of how ant itself sources env variables.
<exec executable="ksh" dir="${foo.dir}"
failonerror="true" output="${foo.dir}/env.properties">
<arg value="-c" />
<arg value=". /usr/local/profiles/profile.foo; set" />
</exec>
<property file="${foo.dir}/env.properties" prefix="env"/>
Further down I can then pass them to sub make calls using the exec tags. For example:
<exec executable="make" dir="${bar.dir}" failonerror="true">
<env key="ORACLE_HOME" value="${env.ORACLE_HOME}" />
</exec>
You will not be able to execute make in the current process.
Take a look at the ant <exec> task, use this to execute your make build. The environment variables will still be available for the make process, in fact you can turn this off explicitly with the newenvironment attribute. The following simple exec should retain all environment variables in make:
<exec executable="make" />
If you need extra environment variables, or want to maintain them through your ant build you can use them in the exec task by adding <env> elements like so:
<exec executable="make" >
<env key="ENV_KEY" value="ENV_VALUE"/>
</exec>
Related
As part of project, I prepared a Ant script which will download files from SVN and copy the files to remote server using scp.
But client asked me to copy only changed files from next deployment onwards in Jenkins instead of copying complete set of 20+ MB files.
got rsync command to do this but here the problem, how to send password from Ant
<exec executable="rsync" dir="/copy-files/js/" failonerror="true">
<arg value="-rcv"/>
<arg value="${username}#server:/media/js/"/>
</exec>
How to pass password from Jenkins, tried with RSYNC_PASSWORD and password-file options but not working.
You can pass values for environment variables by using nested env elements:
<exec executable="rsync" dir="/copy-files/js/" failonerror="true">
<arg value="-rcv"/>
<arg value="${username}#server:/media/js/"/>
<env key="RSYNC_PASSWORD" value="[your.password]" />
</exec>
I can run the following terminal command just fine:
security cms -D -i ../MyMobileProvision.mobileprovision > provision.plist
However, when I run it in Ant, from an ant script in the exact same directory, terminal claims the provisioning file doesn't exist and it creates an empty file for provision.plist, which screws up the next step in my process. The ant code looks like this:
<exec executable="security">
<arg line="cms -D -i ../MyMobileProvision.mobileprovision > provision.plist" />
</exec>
Am I missing something about how ant works? I'm no expert at build scripts but I can use ../ syntax to import properties files just fine, so I'm confused why a relative path isn't working for a terminal command that otherwise would work fine with it.
In your terminal command example, the snippet...
> provision.plist
...is interpreted by your shell as a redirect command.
The <exec> task of Ant doesn't use a shell to execute commands. Instead, the > provision.plist is passed unmodified to the security program.
To get what you want, use the output attribute of <exec>. output is the name of a file where <exec> will write the output:
<exec executable="security" output="provision.plist">
<arg value="cms" />
<arg value="-D" />
<arg value="-i" />
<arg value="../MyMobileProvision.mobileprovision" />
</exec>
In the above example, I've replaced the <arg line="..."> with several <arg value="..."> elements. The reasoning from the Ant documentation on Command-line Arguments:
It is highly recommended to avoid the line version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.
I know the automation of signature for blackberry app, as "java -jar ..signaturetool.jar....",
when I am building using hudson, i have to give at project config page by calling execute windows batch command ant task.
But am writing a build which is common for different clients, that time i want to include
this automation of signing within the build,as my app name will be changed according to the client's name and the path will be changed, so i want to execute this command line within the build, i tried this, but not working, its not executing the exec ant task.
Can anyone help me where am missing, this is the code:
<property name="signpath" location="C:/Program Files/Research In Motion/BlackBerry JDE 5.0.0/bin/SignatureTool.jar"/>
<exec executable ="cmd" os="Windows XP" >
<arg line="java -jar ${signpath} -a -c -p pswd ${codfilepath}/${uid}/${uName}_${version}_${server}.cod"/>
</exec>
I use the following ANT target for signing. It requires the use of bb_ant_tools (which seems to be an industry standard, at least among stackoverflow users).
<target name="sign" depends=""
description="Signs the final COD file by calling the BlackBerry signing server. The password is stored in the common.properties file." >
<sigtool
codfile="${cod.output.dir}/${project.output}.cod"
jdehome="${sigtool.jde}"
password="${sigtool.password}"
/>
</target>
All the parameters are stored in various properties files (I recommend keeping your signature password in a separate properties file to the rest of your project settings).
I would recommend this approach, since bb_ant_tools offers many useful features.
As to why the exec isn't working, I have had problems with exec when putting all parameters in one tag.
Try something like:
<exec executable="java" >
<arg value="-jar" />
<arg value="${signpath}" />
<arg value="-a" />
<arg value="-c" />
<arg value="-p" />
<arg value="pswd " />
<arg value="${codfilepath}/${uid}/${uName}_${version}_${server}.cod" />
</exec>
In my experience, each "space" character in the command line means you need to add a new <arg value="...." /> line to the script. ymmv.
We are facing langOutOfMemory error, when we run an ant script, basically this script runs a lot tests. One solution is to increase heap size using ANT_OPTS variable in environment. But the problem here is I want to increase heap size via ant script itself.
I have tried couple of ways, but neither helped:
<target name="test1">
<exec executable="ant" dir="${TEST}">
<env key="ANT_OPTS" value="-Xmx2048m"/>
</exec>
</target>
<target name="test1" dir="{TEST}">
<exec executable="sh">
<arg line="ant"/>
<env key="ANT_OPTS" value="-Xmx2048m"/>
</exec>
</target>
Please help on this.
Thanks,
Ashok
It looks like you are trying to run ant within ant using the exec. This is pretty convoluted. As document exec is meant to run system commands.
We are facing langOutOfMemory error, when we run an ant script,
basically this script runs a lot tests
Assuming you are running unit tests written in junit using ant junit task, you can use the maxmemory parameter to specify the memory to be used. You should also be setting fork to true.
If this is not the case, please edit the question with the relevant portion of the ant script.
Is it possible specify Ant listener/logger inside build.xml, not on a command line?
Within the buildfile it's possible to make use of the ant api and create an internal task via scriptdef.
i.e. implemented with groovy:
http://josefbetancourt.wordpress.com/2011/08/18/buildlistener-groovy-scriptdef/
http://octodecillion.com/blog/buildlistener-groovy-scriptdef/
It's also possible to adjust the loglevel inside the buildfile, see :
https://stackoverflow.com/a/5464009/130683
https://stackoverflow.com/a/5479606/130683
It's not in the build file, but you can set the ANT_ARGS env variable to specify the logger
http://wiki.apache.org/ant/TheElementsOfAntStyle
Take a look at the Recorder task.
http://ant.apache.org/manual/Tasks/recorder.html
<target name="real-build">
<exec dir="${basedir}" executable="${ant.command}" failonerror="true">
<arg line="-f build-all.xml target ${ant.logger}" />
</exec>
</target>