I am trying to set up a CI/CD for my GitHub repo using CodePipeline. I have set up all stages:
In the Source stage, the action provider is GitHub. It links my repository. The entire code pipeline is able to be triggered from a git push
. It outputs SourceArtifact
.
In the Build stage, I am using AWS Commands as the action provider. My command is: zip -r project.zip ./project
. The output artifact is BuildArtifact
with the file project.zip
.
In the Deploy stage, the action provider is S3 and input artifact is BuildArtifact
. I provide my bucket name and check the box that says: Extract files before deploy
.
After the above configuration, my AWS CodePipeline does technically work. I can push to my repo and trigger the pipeline to execute. The pipeline does successfully execute and uploads the file project.zip
to my S3 bucket. However, I need it to extract the zip file before deployment which is what I thought should happen. I have it checked that it extracts the files before deployment but it’s just uploading the entire zip file to the S3 bucket.
I have not yet found a solution to this online. I tried using CodeBuild for the Build stage with a buildspec.yml
file. however, I’m getting errors that don’t seem to make sense to me like:
Unsupported field "on-failure" in buildspec
and
DOWNLOAD_SOURCE
Failed
CLIENT_ERROR: git fetch failed with exit status 128 for source a1fa55c3_1918_4f54_86e3_59175f50f802
This is the buildspec.yml
I was using:
version: 0.2
phases:
build:
commands:
- zip -r project.zip ./project
artifacts:
files:
- project.zip
So I’m not really sure what is the proper configuration at this point for my pipeline.
2
Answers
The workaround for this was to just have the Build stage of the pipeline perform some meaningless action (like an
ls
). In the Deploy stage, I directly used the output of the Source stage.This isn't the cleanest method, but it works.
Your ZIP file should contain the exact files or folders you want extracted directly at the root of the archive. Use the following command in your Build stage:
Even with the “Extract files before deploy” checkbox enabled, the entire ZIP file might appear unextracted if:
The structure of the ZIP file includes a top-level folder (e.g., project/), so the files are nested in S3 under this folder.
The ZIP file does not meet the S3 deploy action’s expectations, causing the deploy action to upload the ZIP file as-is instead of extracting it.