可以使用以下的bash脚本来解决问题:
image: python:3.6.4-slim-stretch
pipelines:
branches:
master:
- step:
name: Build and Deploy to S3
script:
- apt-get update && apt-get install -y git
- git init
- git remote add origin "YOUR GIT URL"
# Remove unwanted files
- git filter-branch --force --index-filter 'git rm --cached -qr --ignore-unmatch unwanted_folder' --prune-empty --tag-name-filter cat -- --all
# Install dependencies and build your app
- pip install -r requirements.txt
- python build.py
# Configure AWS CLI
- apt-get install -y unzip
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- ./aws/install
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set default.region $AWS_DEFAULT_REGION
# Upload to S3
- aws s3 sync build/ s3://yourbucketname --delete
在脚本中,'unwanted_folder”替换为你需要删除的文件夹名称,上传的S3桶名字替换为你自己的桶名字。此脚本删除了不需要的文件后,上传其他需要文件到S3桶中。