Skip to content

markuschow/citytest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

PCF Roadshow CD Lab - HKG

Intro

This lab will guide you through building a "BASIC" continuous delivery pipeline using Jenkins, Artifactory, and Cloud Foundry.

Setup Steps

  1. FORK (using the GitHub UI) and clone the [citytest repo](https://github.com/cqueiroz-pivotal/citytest):

    $ git clone https://github.com/<YOUR_GIT_USERNAME>/citytest
    $ cd citytest

Login to your Jenkins instance at CloudBees. (if using Cloud Jenkins).

Navigate to Manage Jenkins > Manage Plugins > Available.

Install the following plugins:

Gradle

Mask Passwords

Extensible Choice Parameter Plugin

Artifactory Plugin

Parameterized Trigger Plugin

When you do, tell Jenkins to restart after plugin install.

  1. Login to your Aritfactory Online instance.

  2. Navigate to Admin > Security > General.

  3. Activate encryption for passwords.

  4. Next navigate to Admin > Security > Users.

  5. Create a new user named deployer with a password of your choosing.

  6. Once created, navigate to Admin > Security > Permissions.

  7. Edit the Anything permissions target.

  8. Select the Users tab, and check all permissions for your new user.

  9. Logout, and then log back in as your new user.

  10. Click on the account name in the top right hand corner of the screen.

  11. Enter your password and click Unlock.

  12. Copy your encrypted password and paste it somewhere safe.

  13. Next, send your artifactory details to the CF Jenkins admin (Carlos Queiroz).

    URL

    https://<<your artifactory hostname">[your" class="bare">https://<<your artifactory hostname].artifactoryonline.com/[your artifactory hostname] (e.g. https://cqueiroz.artifactoryonline.com/cqueiroz)

    Username

    the user you created in artifactory

    Password

    the encrypted password you copied a moment ago

Create the Initial Build Job

  1. Navigate back to Jenkins Home (http://pivotal-cloudbees.apj.fe.pivotal.io).

  2. Login with your PCF account.

  3. Click New Job, give it the name citytest-uniquetoken and select ``Build a free-style software project.'' Then click OK. Replace in the script below uniquetoken with something like your username!

  4. Under Source Code Management, select Git, and supply your repository URL (e.g. https://github.com/<YOUR_GIT_USERNAME>/citytest).

  5. Under Build Triggers, select Poll SCM and provide the string * * * * *.

  6. Under Build Environment, select Gradle-Artifactory Integration.

    • Select your Artifactory server.

    • Select libs-releases_local as the Publishing Repository.

    • Ensure the following are checked:

      • Capture and publish build info

      • Allow promotion of non-staged builds

      • Publish artifacts to Artifactory

      • Publish Ivy descriptors

  7. Under Build, add a Invoke Gradle Script build step.

    Gradle Version

    gradle-latest

    Build Step Description

    build environment agnostic artifact

    Switches

    -Pbuildversion=$BUILD_NUMBER

    Tasks

    clean assemble

  8. Save the config and try running the build by clicking ``Build Now''. Ensure that you see the artifact in Artifactory.

Create the Deploy Job

  1. Navigate back to Jenkins Home (http://pivotal-cloudbees.apj.fe.pivotal.io).

  2. Login with your PCF account.

  3. Click New Job, give it the name citytest-uniquetoken-deploy and select ``Build a free-style software project.'' Then click OK.

  4. Check This build is parameterized.

  5. Click Add Parameter and choose Extensible Choice. Make sure to click on the arrow pointing down to allow multiple lines

    Name

    BUILD_VERSION

    Description

    The citytest build to promote.

    Choice Provider

    System Groovy Choice Parameter

    Groovy System Script
    import jenkins.model.*
    import hudson.model.*
    
    def getAllBuildNumbers(Job job) {
      def buildNumbers = []
      (job.getBuilds()).each { build ->
        buildNumbers.add(build.getDisplayName().substring(1))
      }
      return buildNumbers
    }
    
    def buildJob = Jenkins.instance.getItemByFullName('citytest-uniquetoken');
    return getAllBuildNumbers(buildJob)
  6. Under Build Environment, select Generic-Artifactory Integration.

    • Select your Artifactory server.

    • Select ext-releases_local as the Target Repository.

      Resolved Artifacts

      libs-releases-local:citytest-uniquetoken/${BUILD_VERSION}/*⇒artifacts

    • Ensure Capture and Publish Build Info is checked.

  7. Check Mask Passwords, then Add:

    Name

    CF_PASSWORD

    Password

    Your Pivotal Web Services Password

  8. Under Build, add a Execute Shell build step. Remember to replace in the script below uniquetoken with something like your username!

    Command
    #!/bin/bash
    PIVOTAL_WEB_SERVICE_USERNAME="<<<YOUR PWS Username >>>"
    PIVOTAL_WEB_SERVICE_ORGANIZATION="<<<YOUR PWS Organization>>>"
    PIVOTAL_WEB_SERVICE_SPACE="<<<YOUR PWS Space>>>"
    YOUR_UNIQUE_TOKEN="<<< Give a nice unique name for your App>>>"
    
    cf --version
    cf login -a https://api.run.pivotal.io -u ${PIVOTAL_WEB_SERVICE_USERNAME} -p ${CF_PASSWORD} -o ${PIVOTAL_WEB_SERVICE_ORGANIZATION} -s ${PIVOTAL_WEB_SERVICE_SPACE}
    
    DEPLOYED_VERSION_CMD=$(CF_COLOR=false cf apps | grep 'cities-${YOUR_UNIQUE_TOKEN}-' | cut -d" " -f1)
    DEPLOYED_VERSION="$DEPLOYED_VERSION_CMD"
    ROUTE_VERSION=$(echo "${BUILD_VERSION}" | cut -d"." -f1-3 | tr '.' '-')
    echo "Deployed Version: $DEPLOYED_VERSION"
    echo "Route Version: $ROUTE_VERSION"
    
    cf push "cities-${YOUR_UNIQUE_TOKEN}-$BUILD_VERSION" -i 1 -m 512M -n "cities-${YOUR_UNIQUE_TOKEN}-$ROUTE_VERSION" -d cfapps.io -p artifacts/citytest-${BUILD_VERSION}.jar --no-manifest
    
    echo "Is artifacts/citytest-${BUILD_VERSION}.jar exists?"
    pwd
    ls -l artifacts/citytest-${BUILD_VERSION}.jar
    
    cf map-route "cities-${YOUR_UNIQUE_TOKEN}-${BUILD_VERSION}" cfapps.io -n cities-${YOUR_UNIQUE_TOKEN}
    cf scale cities-${YOUR_UNIQUE_TOKEN}-${BUILD_VERSION} -i 2
    if [ ! -z "$DEPLOYED_VERSION" -a "$DEPLOYED_VERSION" != " " -a "$DEPLOYED_VERSION" != "cities-${YOUR_UNIQUE_TOKEN}-${BUILD_VERSION}" ]; then
      echo "Performing zero-downtime cutover to $BUILD_VERSION"
      while read line
      do
        if [ ! -z "$line" -a "$line" != " " -a "$line" != "cities-${YOUR_UNIQUE_TOKEN}-${BUILD_VERSION}" ]; then
          echo "Scaling down, unmapping and removing $line"
          cf scale "$line" -i 1
          cf unmap-route "$line" cfapps.io -n cities-${YOUR_UNIQUE_TOKEN}
          cf delete "$line" -f
        else
          echo "Skipping $line"
        fi
      done <<< "$DEPLOYED_VERSION"
    fi
  9. Save the config and try running the build by clicking ``Build With Parameters''. Select the build you created in the previous step from the drop list. You should see the build deploy to Cloud Foundry.

Create the Trigger

  1. Return to the citytest-unitoken project and click Configure.

  2. Under Post Build Actions add a post-build action, selecting Trigger parameterized build on other projects.

    Projects to build

    citytest-unitoken-deploy

    Predefined parameters

    BUILD_VERSION=$BUILD_NUMBER

  3. Save the config and try running the build by clicking ``Build Now''. You should see both builds executed coupled with a zero-downtime deploy of the app to Cloud Foundry.

Make a Commit and Watch the Pipeline Run

  1. In your local clone of the citytest project, open src/main/java/org/example/cities/VersionController.java in an editor.

  2. Change the version number in the string.

  3. Execute git commit -am "change version number".

  4. Execute git push origin master.

  5. You should see both builds executed coupled with a zero-downtime deploy of the app to Cloud Foundry!

  6. Congrats! You’ve reached the end of the lab.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages