Rashmi Ranjan mallick
Rashmi Ranjan mallick

Reputation: 6620

ANT- How to recursively build the iOS project for different environments?

I am using ANT script to automate my iOS build and packaging tasks. As per my current build script, I am passing the desired environment from command line and the script will generate a IPA file for that particular environment.

Basically, it will run the following targets- ValidateParameters, SetupBuildProperties, SetupXcodeSettings, clean, archive & package.

I have to create builds for Dev, QA & UAT. So, I have to run the script 3 times to have 3 different IPA files. When I pass the environment from command line, I store the same in a ANT property and that will be used in almost all the targets. Because, a property is immutable, that doesn't help me either.

Now, is there any way I can generate all the 3 builds by running the script only once? Not sure how to reset the environment property !!

Please help me.

Upvotes: 2

Views: 252

Answers (1)

M A
M A

Reputation: 72854

One solution is to create a target called something like "buildForAllEnvs" where you invoke a subproject build using antcall for each target environment and passing its property as a nested element:

<target name="buildForAllEnvs">
    <antcall target="runBuild">
        <param name="targetEnv" value="Dev"/>
    </antcall>
    <antcall target="runBuild">
        <param name="targetEnv" value="QA"/>
    </antcall>
    <antcall target="runBuild">
        <param name="targetEnv" value="UAT"/>
    </antcall>
</target>

Note that there are many ways to override or reset properties in Ant. See How to over-write the property in Ant?:

  1. Using Ant-Contrib's var task (requires adding Ant-Contrib to your classpath, which also introduces a bunch of useful tasks for conditional execution using if and looping using for).
  2. Using macrodefs to reuse the same build with different parameters.
  3. Manually overriding the property using the project API (hacky though).

Upvotes: 1

Related Questions