Blog

Akamai Pipeline and Jenkins

How-To: Using Jenkins and Akamai Pipeline Together

October 10, 2018 · by James Chin ·

If you haven’t read the blog post on Move Faster with Akamai Pipeline and Federated Configuration Development, it does a great job describing how to promote changes through different development environments. This post goes into more detail on how to set up the pipeline described there. These features are part of the Akamai 2018 October Release.

What’s Akamai Pipeline?  

Akamai CLI for Property Manager is a new CLI package designed to create a client-side version of the Akamai Property Manager UI. Akamai Pipeline is a capability within this CLI that lets you take a configuration and easily propagate changes through a pipeline of your local environments (for example, dev, qa, shared, staging, production).  

This CLI package helps simplify how you interact with your Akamai configurations and the akamai pipeline command makes it easier to make changes across environments. It gives you both the power and flexibility to promote property configuration changes via a single command.

The focus of Akamai Pipeline is to promote environment changes to the Akamai network, so it’s a natural fit to integrate this within an automation (CI/CD) server.  Specifically, we're referencing Jenkins here, a popular open-source automation server.

In this blog post, I’ll show you how to set up Akamai Pipeline with Jenkins and walk through an example use case.

Using Jenkins and Akamai Pipeline Together

In this use case, I have a predefined pipeline with “dev”, “qa”, and “prod” environments that need to correspond with “developer”, “qa”, and “production” branches on a Bitbucket server. The final piece of the puzzle is the Jenkins server, which is configured to work with the developer and qa branches and environments.

I’ll show you how to set up a Jenkins/stash server that supports the following use case:

  1. You make changes on your Akamai configuration locally on the “developer” branch and promote them onto the Akamai network.

  2. A developer on your team reviews changes, and pushes the changes to the develop branch with a commit and push to the repo.

  3. Jenkins picks up the changes on the develop branch and kicks off a “merge-develop-to-qa” job, which tries to merge develop to qa branch and push the results back to the repository

  4. If successful, the “merge-develop-to-qa” job kicks off the “promote qa” job, which uses Akamai Pipeline to activate the configuration.

Setting Up Your Integration Environment

If you want to try this on your own, here’s a brief section describing how to set up this integration environment and what you need.

  • An installed akamai property-manager Module for the Jenkins user on your Jenkins machines. This should also be installed for the user using the CLI for local testing.

    1. The following link will get you started with the akamai pipeline https://github.com/akamai/cli-property-manager#get-started

    2. For Jenkins, add a /var/lib/jenkins/.bashrc with this content

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
 

  • Installation of a Jenkins server

    1. The following link has instructions on how to install Jenkins for different OS platforms. This example uses an Ubuntu server 

      https://jenkins.io/doc/book/installing/#debian-ubuntu

    2. Start Jenkins up with systemctl start Jenkins

    3. Be sure to do the standard plugins, or at the very least make sure the “git plugin” is installed.

  • Installation of a bitbucket server

    1. Install a bitbucket server

      https://confluence.atlassian.com/bitbucketserver/bitbucket-server-installation-guide-867338382.html

    2. Install the “Bitbucket Server Webhook to Jenkins” plugin. This allows Bitbucket to inform Jenkins of code pushes to the repository.

  • A repository in Git with the following branches, with a Akamai Pipeline project checked into the branches. The pipeline can be from scratch or it can also be an existing pipeline.

    1. “develop”, “qa”, “production”

    2. Check into git the pipeline project folder (not just the contents of the folder).

Configuring Your Environments

Bitbucket Plugin

This plugin does a push to Jenkins every time a change is made in the repository. There are other ways of getting Jenkins to build, but this is a direct way to get your build to process in Jenkins with a code push.

For your repository, under Repository settings > workflow > hooks > post receive is the Bitbucket Server Webhook to Jenkins plugin. Please enable that, and configure it to point to your repository.jenkins

As a side note, in the advanced configuration the committers are referring to the bitbucket user pushing to the bitbucket server. It is not the git usernames making the commits.

Jenkins Jobs Configuration

You will have two Jenkins jobs working together to have a basic building block for any environment stage.  

  1. The first job will try to merge the develop branch to the qa branch. Upon success, the first job will trigger the “promote job”.

  2. When the “merge job” finishes, the “promote job” will try to promote the pipeline from the qa branch, and when activated commit the results back to qa.

Configure the “promote-qa” Job
Create and configure a new “Freestyle Project”.

Configure the Repository Settings
Jenkins

 

  1. In the Source Code Management section, choose git as your repo.  

  2. Give it a name so you can reference the repository in this job.  

  3. Build the branch for the “qa” branch.

  4. This time, you’ll add the Don’t trigger a build on commit notifications behavior so that the “merge job” is the only thing that triggers this job.

Configure the Build Steps
Jenkins

 

  1. Create an “execute shell” command with the following to load nvm and promote to qa

    • source /var/lib/jenkins/.bashrc && akamai pipeline promote -w -e someone@somewhere.com -p jenkinspipeline -n p qa

    • The “-w” option will wait until the activation is complete before returning

  2. Create an “execute shell” command with the following

    • git add -A && git commit -m 'build success.  committing files'

    • Add any new and modified files, and commit it.

      Configure the Post-build actions Jenkins

       

  3. Just push the results of the commit back to qa. This will happen regardless if the build failed or not, since you will always want to save the state of qa.

Configure the “merge-develop-to-qa” Job
Create and configure a new “Freestyle Project”.

Configure General Job Settingsjenkins

 

  1. Click Advanced, and add on Block build when downstream project is building. This is to ensure that you don’t merge to the qa environment while the qa job is in the middle of promoting.

Configure the repository settings jenkins
 

  1. In the Source Code Management section choose git as your repo.  

  2. Give it a name so you can reference the repository in this job.  

  3. Build the branch for “develop” branch.

  4. Merge the build to qa.

Configure the Build Triggers

There are many ways to configure how your build is triggered. In this example, you will rely on the Bitbucket Server Webhook to Jenkins to do a push. In order for the bitbucket plugin to work however you need to enable scm polling. No need to set a schedule.  

Note: Only polling triggered by a schedule (not a posthook trigger from bitbucket) can Jenkins ignore git users/file paths/git messages.jenkins

Configure the Post-build Actions
jenkins-8

 

  1. Enable merge results and push it back to the repository

  2. Trigger the promote-qa job

You Created a Basic Jenkins Pipeline for QA!

This is a basic “building block” of how to use Jenkins with Akamai Pipeline.  With this setup, you’ve accomplished a couple of things:

  • This allows the developer to only need to worry about changes to the develop branch and not any downstream changes from the environments from qa or production.

  • Second, this allows Jenkins to automatically build to the qa environment based on the check-ins from the developer.  You can also use this “building block” to add more stages/environments to the Jenkins pipeline.

Lets say you have an Akamai pipeline already set up with jenkins and want to make some changes. Because you are working with Jenkins that will promote to the downstream environments, you need to make changes to any downstream environments in this commit as well. In this example, changes would be needed in
jenkins-pipeline/environments/dev/variables.json,
jenkins-pipeline/environments/qa/variables.json, and
jenkins-pipeline/environments/prod/variables.json files.  
After modifying these files, you would promote them to the dev environment on the production network.jenkins

Here you would use the  -w option which after it tries to activate the configuration for the dev environment, it does a 1 minute poll to see when its activated.

Commit and push the changes to the develop branch

After it’s activated, examine the live changes. When ready you would commit back to the develop branch and push the changes back to origin.jenkins-10

The Jenkins “merge-develop-to-qa” job Kicks Off

Here Jenkins picks up the change from the develop branch and kicks off the “merge-develop-to-qa” job.  Its primary job is to merge the develop branch to qa and kick off the “promote-qa” job.jenkins

The Jenkins “promote-qa” Job Runs

This job tries to promote the qa branch, which now has the latest merge from the develop branch.Jenkins

 After the configuration is activated, the job commits back to qa.Jenkins

And that’s how Jenkins promotes to qa from a developer push to the develop branch.

Add More Environments and Pipelines!

It’s possible to add more stages/environments to automatically build by using the basic “block” of jobs.  The first job merges to the next environment, and the second job promotes the next environment. For example if you needed to have Jenkins promote to staging you could do the following:

  1. a “merge-qa-to-staging” job which merges qa branch to a staging branch, and then kicks off a “promote-staging” job

  2. A “promote-staging” job which uses promotional deployment to promote to staging, and commit the result back to the staging branch.

The “merge-qa-to-staging” job could be triggered from a successful “promote-qa” job, or it can just be manually kicked off as well.  With this “block” of merge and promote jobs you can add on any number environments to build.

Give it a Try!

Now that I’ve shown you how to create a pipeline and how to link pipelines together, you can pair the Akamai Pipeline capability with your Jenkins instance. This enables you to completely automate the deployment of your Akamai changes to different environments, saving you on time and energy, and making you more productive. And if you have any questions, don’t miss the chance to join our webinar on Thursday, October 30th at 10am PDT, where we’ll walk you through a live demo of Akamai Pipeline, along with a chance to ask questions live. Register now.

Additional Resources