2016-06-08 103 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