Jenkins + Bitbucket + AWS EC2 + CodeDeploy

Prerequisite:

Make sure you already config AWS CodeDeploy for your desired AWS EC2 server. Check this blog if you want to set it up.

Steps:

  1. Install Jenkins Plugins: Amazon Web Services SDK , AWS CodeDeploy Plugin for Jenkins , Bitbucket Plugin
  2. Generate key, if you don’t have one already:

$ ssh-keygen -o -a 100 -t ed25519

  1. Add public key into bitbucket Access Keys list:

  1. Add bitbucket webhook to notify Jenkin

  1. Add private key into Jenkins:

  1. Go to AWS console and generate a AWS access key:
    AWS Access and Secret keys to use for this deployment. At minimum the keys must be allowed to execute codedeploy:* and s3:Put* . It’s a best practice to have these keys be from an IAM role with limited scope.

If your Jenkins install is running on an EC2 instance with an associate IAM role, you can leave these fields blank. You will just need to ensure that the role has the correct policies.

  1. Add AWS access and secret keys to Jenkins:

  1. In Jenkins configuration, click Build when a change is pushed to BitBucket and Add timestamps to the Console Output

  2. Add Post-build Action -> Deploy an application to AWS CodeDeploy

  1. finish and test
    Go ahead and testing your whole workflow by pushing some noticeable code changes to bitbucket.

Reference

upgrade-your-ssh-keys

Jenkins with BitBucket

integration-of-aws-codedeploy-with-jenkins

aws-codedeploy-plugin

saving-money-with-jenkins-digital-ocean-and-docker

1 comment

Leave a Reply