Balaji Vajjala's Blog

A DevOps Blog from Trenches

04.03

  • 4.3 Script a build in Ant
    • Learning Objectives
    • EXERCISE: Run Ant build
    • EXERCISE: Create a Rake build script (OPTIONAL)

4.3 Script a build in Ant

Learning Objectives

By the end of this lesson you will be able to:

  • Script a build that packages software so that it can be deployed.

EXERCISE: Run Ant build

  1. From the AWSCLI, install using yum

    “` $ sudo yum -y install ant

    “`

  2. Go to the build directory.

    cd /home/ec2-user/continuous_integration_example/software/build

  3. Type ant from the command line

    ant

    You should receive a message like this:

    Buildfile: build.xml does not exist! Build failed

  4. From the build directory, create an Ant build file called myantbuild.xml

    “` $ sudo vim myantbuild.xml

    “`

  5. Create an Ant project within the myantbuild.xml file

    “` <?xml version=“1.0” encoding=“iso-8859-1”?>

    “`

  6. Define properties between the project tags.

    “`

    “`

  7. Define targets after the property definitions

    “`

    “`

  8. Add tasks to targets (within the compile-src target)

    “`

    “`

  9. Define dependent targets

    <target name="all" depends="compile-src">

  10. The entire myantbuild.xml file should look like this:

    “`

    <?xml version=“1.0” encoding=“iso-8859-1”?>

    “`

  11. Run myantbuild.xml file from the command line

    “` $ ant -f myantbuild.xml

    “`

  12. Add the file in Git

    “` $ git add .

    “`

  13. Commit the file to Git

    “` $ git commit -m “Modified build script”

    “`

  14. Push it to the Git master.

    “` $ git push

    “`

EXERCISE: Create a Rake build script (OPTIONAL)

  1. From your AWSCLI instance go to sample_app, open some build scripts.
  2. You can also find these files by going to https://github.com/stelligent/sample_app/blob/master/Rakefile and https://github.com/stelligent/sample_app/blob/master/lib/tasks/sample_data.rake.
  3. Make a modification to the contents of the file and save it.
  4. Add the file in Git

    “` $ git add .

    “`

  5. Commit the file to Git

    “` $ git commit -m “Modified build script”

    “`

  6. Push it to the Git master.

    “` $ git push

    “`