Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy application using Jenkinsfile and AWS Code deploy

I am migrating from Jenkins 1.x to Jenkins 2. I want to build and deploy application using Jenkinsfile. I am able to build gradle application, but I am confused about deploying application via AWS Codedeploy using Jenkinsfile.

Here is my jenkinsfile

node {
   // Mark the code checkout 'stage'....
   stage 'Checkout'
   // Get some code from a GitHub repository
      git branch: 'master', 
       credentialsId: 'xxxxxxxx-xxxxx-xxxxx-xxxxx-xxxxxxxx', 
       url: 'https://github.com/somerepo/someapplication.git'

   // Mark the code build 'stage'....
   stage 'Build'
   // Run the gradle build
      sh '/usr/share/gradle/bin/gradle build -x test -q buildZip -Pmule_env=aws-dev -Pmule_config=server'

    stage 'Deploy via Codedeploy'
    //Run using codedeploy agent
}

I have searched many tutorial but they're using AWS Code deploy plugin instead. Could you help me deploying application via AWS Codedeploy using Jenkinsfile?

Thank you.

like image 240
user1693222 Avatar asked Jun 08 '16 06:06

user1693222


1 Answers

Alternatively you can use AWS CLI commands to do code deployment. This involves two steps.

Step 1 - Push the deployment bundle to S3 bucket. See the following command:

aws --profile {profile_name} deploy push --application-name {code_deploy_application_name} --s3-location s3://<s3_file_path>.zip

Where:

  1. profile_name = name of AWS profile (if using multiple accounts)
  2. code_deploy_application_name = name of AWS code deployment application.
  3. s3_file_path = S3 file path for deployment bundle zip file.

Step 2 - Initiate code deployment The second command is the used to trigger code deployment. See the following command:

aws --profile {profile} deploy create-deployment  --application-name {code_deploy_application_name} --deployment-group-name {code_deploy_group_name} --s3-location bucket={s3_bucket_name},bundleType=zip,key={s3_bucket_zip_file_path}

Where:

  1. profile = name of your AWS profile (if using multiple accounts)
  2. code_deploy_application_name = same as step 1.
  3. code_deploy_group_name = name of code deployment group. This is associated with your code deploy application.
  4. s3_bucket_name = name of S3 bucket which will store your deployment artefacts. (Make sure that your role that performs code deploy has permissions to s3 bucket.)
  5. s3_bucket_zip_file_path = same as step 1.
like image 111
Suken Shah Avatar answered Sep 28 '22 16:09

Suken Shah