1

I am updating an ant script to specify a testLevel argument. However we'd like to have this argument be optional.

I'm fairly new to ant and wondering if theres a way to conditional see if the argument is passed in and if not to default to NoTestRun

<target name="deploy">
   <sf:deploy username="${user}" password="${pass}" serverurl="${url}"
        maxPoll="${maxPoll}" pollWaitMillis="${pollWaitMillis}"
        deployRoot="${basedir}/src" testLevel="${testLevel}" checkOnly="${checkOnly}" />
</target>
1

You can set the property using property.

<target name="deploy">
   <property name="testLevel" value="NoTestRun" />
   <sf:deploy username="${user}" password="${pass}" serverurl="${url}"
        maxPoll="${maxPoll}" pollWaitMillis="${pollWaitMillis}"
        deployRoot="${basedir}/src" testLevel="${testLevel}" checkOnly="${heckOnly}" />
</target>

The trick with property is that they are immutable, meaning a property can be set only once. If it was set by command-line or an env task previously, the property tag will have no effect. Otherwise, it will be set and the value will be NoTestRun.

  • After applying this update without specifying testLevel in the command line, it spits out an error. '${testLevel}' is not a permitted value for testLevel.You must specify testLevel from following options: 1. NoTestRun 2. RunSpecifiedTests 3. RunLocalTests 4. RunAllTestsInOrg – TemporaryFix Nov 29 '16 at 20:14
  • @Programatic Check for spelling errors. It's also cAsE sEnSiTiVe, as in Java. – sfdcfox Nov 29 '16 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.