2016-06-08 134 views
3

我正在从Jenkins 1.x迁移到Jenkins 2.我想使用Jenkinsfile构建和部署应用程序。 我能够构建gradle应用程序,但我对使用Jenkinsfile通过AWS Codedeploy部署应用程序感到困惑。使用Jenkinsfile和AWS Code部署应用程序部署

这里是我的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 
} 

我已经搜索很多教程,但他们正在使用AWS代码部署插件来代替。 您可以帮助我使用Jenkinsfile通过AWS Codedeploy部署应用程序吗?

谢谢。

回答

3

或者,您可以使用AWS CLI命令执行代码部署。这涉及两个步骤。

步骤1 - 将部署捆绑包推送到S3存储桶。请参见下面的命令:

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

其中:(如果使用多个帐户)AWS轮廓

  1. PROFILE_NAME =名称
  2. code_deploy_application_name = AWS代码部署应用程序的名称。
  3. s3_file_path =部署捆绑zip文件的S3文件路径。

步骤2 - 启动代码部署 第二个命令是用于触发代码部署。请参见下面的命令:

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}

其中:(如果使用多个帐户)您的AWS轮廓

  1. 配置=名称
  2. code_deploy_application_name =同步骤1
  3. code_deploy_group_name =名称代码部署组。这与您的代码部署应用程序相关联。
  4. s3_bucket_name =将存储部署文物的S3存储桶的名称。 (请确保执行代码部署您的角色有权S3桶。)
  5. s3_bucket_zip_file_path =同步骤1