Search code examples
ant

How can I pass a default value via command line when running ant?


    <target name="clone-repo" description="Pull code from SCM repository" depends="resolve">
            <taskdef resource="org/eclipse/jgit/ant/ant-tasks.properties" classpathref="build.path"/>
            <delete dir="${basedir}/omoc_build"/>
            <git-clone uri="https://user:******@github.com/sirect/omoc.git" dest="${basedir}/omoc_build" branch="${branch}" />
            <zip destfile="${basedir}/devtoolkit/devtoolkit_docker/config.zip" basedir="${basedir}/omoc_build/config" />

I want to run ant command where by default it should clone from main branch


Solution

  • Few things! To answer your question, you can set the branch property in a properties file, which would be overwritten if you specify on commandline. Include the property file above your target:

    <property file="defaults.properties" description="default configuration."/>
    

    in defaults.properties you'll set branch to main and you could overide it with -Dbranch=non-main-branch

    That allows you to set a default.

    Now for the advice you didn't ask for: Don't want ant cloning your source. You should have your build system checkout the source and then ant should build the source. You're creating a chicken and egg problem here... build.xml is in source control, and it's checking out source? That's fishy.