简体   繁体   中英

Jenkins: Deploy application to an EC2 instance

I've been working on a cloud formation template for my environment. I end up with a

  • VPC
  • Subnet x2
  • Autoscaling group
  • Launch configuration (EC2 instances on AWS Linux AMI)
  • Application load balancer
  • Codedeploy (for deployments)

But I incurred problem with CodeDeploy configuration with Cloud Formation, as not all features are possible for EC2 instances. After configuring manually CodeDeploy, I get an error while deploying such as "too few unhealthy instances" after which created instances are not destroyed even if rollback is enabled. I'm using right now only one EC2 instance for application, but planning in future to scale.

Is there an alternative for CodeDeploy? I'm interested to trigger deploy from Jenkins Machine.

For above your requirements, I strongly suggest that using aws elastic beanstalk is better way to deploy codes to aws. Because we could manage those in elastic beanstalk and for code deployment, use codeship is also better way to mange deployment integrated with github instead of aws code deployment.

Ensure that you have assigned the correct IAM role for the EC2 instance by going to the "Instance Settings". This will ensure that your deployment occurs smoothly without throwing that error.

You can also configure the deployment to EC2 using CodeDeploy through jenkins.

Steps to follow:

AWS CodeDeploy:

  1. Create a new CodeDeploy application.
  2. Enter a suitable application name and choose "EC2/On premises" as the compute pleatform.
  3. Add a deployment group under the application. For eg: "test".
  4. Choose in-place deployment.
  5. Add service role as "Codedeploy development". This will allow codedeploy to interact with other AWS services.
  6. Choose a suitable deployment configuration preferably: "OneAtATime" if deploying to a single EC2 instance.
  7. Environment configuration: Choose the EC2 instance in which you want to deploy the application

Jenkins:

  1. On Jenkins, create a job with a suitable application name.
  2. In the "Post Build Action" section, click on "Add Post Build Action" Jenkins - post build configuration
  3. Choose: "Deploy an application to AWS CodeDeploy"
  4. Enter the CodeDeploy and S3 details in the section
  5. S3 bucket will contain all the builds which is used to deploy onto EC2 using Codedeploy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM