You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS EC2上Bitbucket Pipeline未部署最新代码问题咨询

Troubleshooting: EC2 CodeDeploy Not Updating to Latest Code (Bitbucket Pipelines Setup)

Let's walk through the most likely issues and fixes here—since your Bitbucket pipeline reports success and S3 has the latest bundle, the problem is almost certainly happening on the CodeDeploy or EC2 side.

1. Confirm CodeDeploy Actually Triggered a Deployment

First, rule out if the deployment even reached AWS CodeDeploy:

  • Head to the AWS CodeDeploy Console > Deployments and look for the latest deployment tied to your pipeline run.
    • If it’s marked Failed or In Progress, click into it to view detailed error messages.
    • If there’s no matching deployment entry, double-check the aws deploy create-deployment command in your bitbucket-pipelines.yml:
      • Ensure the $APPLICATION_NAME and $DEPLOYMENT_GROUP_NAME variables in Bitbucket exactly match the names in AWS CodeDeploy. Typos here can cause the command to exit successfully without creating a deployment.

2. Check the CodeDeploy Agent Health on EC2

The CodeDeploy agent on your Ubuntu instance needs to be running and authorized to pull the bundle from S3:

  • SSH into your EC2 instance and run:
    sudo systemctl status codedeploy-agent
    
  • If it’s stopped, start it with:
    sudo systemctl start codedeploy-agent
    
  • Enable it to auto-start on instance reboot:
    sudo systemctl enable codedeploy-agent
    
  • Also, verify the EC2 instance’s IAM role has the s3:GetObject permission for your deployment bucket—without this, the agent can’t download the bundle.

3. Validate Your AppSpec.yml Configuration

Your appspec.yml has a few critical points to check:

  • Files Section: The source: / tells CodeDeploy to copy all bundle files to /home/ubuntu/aok. Ensure:
    • The /home/ubuntu/aok directory exists on EC2. If not, CodeDeploy might fail silently (check logs for this). You can add a pre-hook to create the directory if needed.
    • The CodeDeploy agent (running as the codedeploy user) has write access to this directory. Your permissions section sets owner/group to ubuntu, but confirm the agent can write here.
  • Hook Scripts: The AfterInstall hooks run install_dependencies and start_server. Verify:
    • These scripts exist in your deployment bundle under the scripts/ folder (download the S3 zip to confirm).
    • They’re executable. Test them manually on EC2:
      sudo /home/ubuntu/aok/scripts/install_dependencies
      sudo /home/ubuntu/aok/scripts/start_server
      
    • If start_server doesn’t properly restart your MEAN app (e.g., it starts a new process without killing the old one), the original app instance may still be serving outdated content.

4. Dig Into CodeDeploy Logs on EC2

The most detailed error info lives in EC2’s CodeDeploy logs:

  • Check the agent log at:
    cat /var/log/aws/codedeploy-agent/codedeploy-agent.log
    
  • Check deployment-specific script logs at:
    cat /opt/codedeploy-agent/deployment-root/<deployment-group-id>/<deployment-id>/logs/scripts.log
    
  • Look for red flags like:
    • Permission denied errors when writing to the destination directory
    • Scripts exiting with non-zero codes
    • Missing files or incorrect source paths

5. Verify the Deployment Bundle Content

Even if S3 has the latest code, double-check the bundle itself:

  • Download aok.zip from S3, unzip it locally, and confirm your latest changes are present.
  • Your aws deploy push command uses --ignore-hidden-files—if your MEAN app relies on hidden files (like .env), they won’t be included. Remove this flag if needed.

6. Ensure the MEAN App Serves the Correct Directory

Finally, confirm your MEAN app’s server is configured to serve files from /home/ubuntu/aok. If it’s using a symlink that wasn’t updated, or pointing to an old directory, it will continue to show outdated content.


内容的提问来源于stack exchange,提问作者ah92

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 11:24:07