Browse the Repo

file-type-icon.circleci
file-type-icon_ci
file-type-icon_docs
file-type-iconexamples
file-type-iconiam-policies
file-type-iconjenkins
file-type-iconmock
file-type-iconpacker
file-type-iconuser-data
file-type-iconREADME.md
file-type-icondocker-compose.yml
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconmodules
file-type-icontest
file-type-icontestdep
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME-CircleCI.adoc
file-type-iconREADME-Jenkins.adoc
file-type-iconREADME-TravisCI.adoc
file-type-iconREADME.adoc

Browse the Repo

file-type-icon.circleci
file-type-icon_ci
file-type-icon_docs
file-type-iconexamples
file-type-iconiam-policies
file-type-iconjenkins
file-type-iconmock
file-type-iconpacker
file-type-iconuser-data
file-type-iconREADME.md
file-type-icondocker-compose.yml
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconmodules
file-type-icontest
file-type-icontestdep
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME-CircleCI.adoc
file-type-iconREADME-Jenkins.adoc
file-type-iconREADME-TravisCI.adoc
file-type-iconREADME.adoc
Jenkins

Jenkins

Deploy Jenkins and configure CI / CD pipelines for your apps as code using Jenkinsfiles and Gruntwork build and deploy scripts.

Code Preview

Preview the Code

mobile file icon

README.md

down

Jenkins example

This folder shows an example of how to use the jenkins-server, install-jenkins, and ec2-backup modules to deploy a Jenkins CI server in AWS. The server will run on top of an Auto Scaling Group (for high availability), with an ALB and domain name, an EBS volume to persist data between redeploys, and a Lambda function that will take automatic nightly snapshots of the EBS volume for backup.

Quick start

To run this example, you need to:

  1. Build a Jenkins AMI
  2. Deploy the Jenkins AMI with Terraform
  3. Login to Jenkins

Build a Jenkins AMI

We create an AMI that has Jenkins and its dependencies installed using the Packer template under packer/jenkins.json. To build the AMI:

  1. Set up your AWS credentials as environment variables.
  2. Set the GITHUB_OAUTH_TOKEN environment variable to a valid GitHub auth token with "repo" access. You can generate one here: https://github.com/settings/tokens
  3. In packer/jenkins.json, configure the AWS region you want to use via the aws_region variable.
  4. To run Jenkins on Ubuntu: packer build -only=ubuntu-ami packer/jenkins.json.
  5. To run Jenkins on CentOS: packer build -only=centos-ami packer/jenkins.json.

Note down the ID of the new AMI, as you'll need it in the next section.

Deploy the Jenkins AMI with Terraform

We have created Terraform configurations to deploy the AMI from the previous step in AWS. To deploy the Terraform code:

  1. Open vars.tf, set the environment variables specified at the top of the file, and fill in any other variables that don't have a default:
    1. ami_id: Set this to the ID of the AMI you built in the previous section.
    2. hosted_zone_domain_name: Set this to a domain name for which you have a Public Hosted Zone in Route 53. You will also need to request a free wildcard TLS certificate for this domain name using AWS Certificate Manager: e.g., if the domain name is foo.com, you'll need to request a free certificate for *.foo.com. Getting a cert is a very easy process that takes only a couple minutes: instructions.
    3. key_pair_name: The EC2 Key Pair to associate with the Jenkins server. You'll need access to this EC2 Key Pair so you can SSH to the server later.
  2. Run terraform init.
  3. Run terraform plan.
  4. If the plan looks good, run terraform apply.

When apply finishes, it'll output the domain name of your server. Head over to that URL and you'll be prompted to login to Jenkins.

Login to Jenkins

When you first load Jenkins, it will ask you to enter the initial admin password to unlock it. This password is located on the Jenkins server itself and the initial login page will show you the path (typically, /jenkins/secrets/initialAdminPassword). You'll need to SSH to the server to get the password.

Local testing

The Packer template in packer/jenkins.json can build not only an AMI, but also a Docker image with Jenkins installed. You can run this Docker image on your local computer for faster ("unit") testing:

  1. Set the GITHUB_OAUTH_TOKEN environment variable to a valid GitHub auth token with "repo" access. You can generate one here: https://github.com/settings/tokens
  2. To run Jenkins on Ubuntu:
    1. packer build -only=ubuntu-docker packer/jenkins.json
    2. docker-compose run --service-ports jenkins_ubuntu
  3. To run Jenkins on CentOS:
    1. packer build -only=centos-docker packer/jenkins.json
    2. docker-compose run --service-ports jenkins_centos

The docker-compose.yml in this folder will run the scripts in the mock folder to mock out a few dependencies and boot up Jenkins locally on port 8080. After a few seconds, you should be able to test it by going to http://localhost:8080.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?