Balaji Vajjala's Blog

A DevOps Blog from Trenches

06.03

  • 6.3 Configure a scripted environment job
    • Learning Objectives
    • EXERCISE: Create a Jenkins job that builds a new environment

6.3 Configure a scripted environment job

Learning Objectives

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

  • Create a new job in Jenkins that builds an environment using the AWS infrastructure and CloudFormation.

EXERCISE: Create a Jenkins job that builds a new environment

  1. From the Jenkins dashboard, select the New Job link.
  2. Enter MyTargetEnvironment in the Job name field. Click on the Build a free-style software project radio button and click the OK button.
  3. Select the checkbox next to This build is parameterized. Enter a String Parameter type and give it the name STACK_NAME. Enter your student id for the Default Value text field.
  4. Enter another String Parameter type and give it the name PrivateBucket. Enter cd29creds (where 29 is your student id) for the Default Value text field.
  5. Enter another String Parameter type and give it the name PublicBucket. Enter cd29artifacts (where 29 is your student id) for the Default Value text field.
  6. Enter another String Parameter type and give it the name KeyName. Enter cd29 (where 29 is your student id) for the Default Value text field.
  7. Under the Source Code Management section, select the Git radio button. In the Repository URL field, enter your forked repository URL. Yours will be something like student03, student08, etc. For example:

    git@github.com:student29/continuous_integration_example.git

  8. In the Branches to build | Branch Specifier field, enter **

  9. Within the Build Environment section, click on the Create AWS Cloud Formation stack checkbox.
  10. In the Cloud Formation recipe file. (.json) field, enter:

    software/infrastructure/target.template

  11. In the Stack name field, enter:

    ${STACK_NAME}

  12. In the Stack description field, enter:

    stack

  13. Leave Cloud Formation parameters field, enter:

    PrivateBucket=${PrivateBucket},PublicBucket=${PublicBucket},KeyName=${KeyName}

  14. In the Timeout (seconds) field, enter:

    900

  15. In the AWS Access Key field, enter:

    $AWS_ACCESS_KEY

  16. In the AWS Secret Key field, enter:

    $AWS_SECRET_ACCESS_KEY

  17. Leave the Automatically delete the stack when the job completes checkbox unchecked:

  18. Within the Build section, enter the following command in the Execute shell text field.

    ruby /usr/share/tomcat6/scripts/aws/create_domain.rb ${STACK_NAME} echo "artifact_bucket=$(eval "echo \$${STACK_NAME}_ArtifactBucket")" >> /tmp/properties echo "ip_address=$(eval "echo \$${STACK_NAME}_InstanceIPAddress")" >> /tmp/properties echo "stack_name=$(eval "echo \$${STACK_NAME}_StackName")" >> /tmp/properties ruby /usr/share/tomcat6/scripts/aws/load_domain.rb ${STACK_NAME}

  19. Click the Save button.

  20. Go back to the Jenkins dashboard and click the Build button next to the MyTargetEnvironment job.