Got weird error while referencing from Codebuild source = buildspec.yml
See original GitHub issue❓ General Issue
The Question
I try to use codebuild with compose docker in docker and deploy to ECR hub.
While using buildSpec: BuildSpec.fromSourceFilename
I encountered this error:
If the Project's source is NoSource, you need to provide a concrete buildSpec
xxxProject/node_modules/constructs/lib/construct.ts:407
throw new Error(`Validation failed with the following errors:\n ${errorList}`);
^
Error: Validation failed with the following errors:
[Bob-Pipeline-dev] Stage 'Build' must have at least one action
If I use buildSpec: BuildSpec.fromObject
, it works @@, no idea
Environment
- CDK CLI Version: 1.32.1
- OS: : OSX Catalina
- Language: Typescript
Sample code with buildspec.yml
File structure:
File: pipeline.ts
const pipeline = new Pipeline(
this,
`Pipeline-${environment.ENV}`,
{
pipelineName: `pipeline-${environment.ENV}`,
},
)
const sourceStage = pipeline.addStage({
stageName: 'Source',
})
const buildStage = pipeline.addStage({
stageName: 'Build',
placement: {
justAfter: sourceStage,
},
})
const sourceOutput = new Artifact()
const sourceAction = new GitHubSourceAction({
actionName: `codebuild-action-${environment.ENV}`,
owner: 'xxx,
repo: 'xxx',
oauthToken: cdk.SecretValue.secretsManager('tGitHubToken'),
output: sourceOutput,
branch: `${environment.branch}`,
trigger: GitHubTrigger.WEBHOOK,
})
sourceStage.addAction(sourceAction)
const buildRole = new iam.Role(
this,
`IamRole-${environment.ENV}`,
{
assumedBy: new iam.ServicePrincipal('codebuild.amazonaws.com'),
},
)
const codeBuild = new Project(
this,
`CodeBuildProject-${environment.ENV}`,
{
role: buildRole,
environment: {
buildImage: LinuxBuildImage.fromDockerRegistry('docker:dind')
},
buildSpec: BuildSpec.fromSourceFilename('./buidspec.yml')
const buildAction = new CodeBuildAction({
actionName: 'Build',
input: sourceOutput,
project: codeBuild,
})
buildStage.addAction(buildAction)
}
File: buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
nodejs: 12
python: 3.8
commands:
- apk add --no-cache python py-pip jq
- pip install awscli
- echo $AWS_ACCESS_KEY_ID
- echo $AWS_SECRET_ACCESS_KEY
build:
commands:
- $(aws ecr get-login --no-include-email --region ${AWS_REGION_ECR})
- |
for dir in `find packages -type d -mindepth 1 -maxdepth 1 -not -name utils -not -name types -exec basename {} \;`;
do
docker build -f Dockerfile.${dir} -t ${REPOSITORY_URL}:${dir} .
docker push ${REPOSITORY_URL}:${dir}
done
post_build:
commands:
- i=1
- CURRENT_SERVICE_COUNT=`aws ecs list-services --region ${AWS_REGION_ECS} --cluster ${CLUSTER_NAME} | jq --raw-output ".serviceArns" | jq length`
- CURRENT_SERVICES=`aws ecs list-services --region ${AWS_REGION_ECS} --cluster ${CLUSTER_NAME} | jq --raw-output ".serviceArns"`
- |
while [ "$i" -le "$CURRENT_SERVICE_COUNT" ]; do
SERVICE=`echo $CURRENT_SERVICES | jq --raw-output ".[$i-1]"`
aws ecs update-service --region ${AWS_REGION_ECS} --service ${SERVICE} --cluster ${CLUSTER_NAME} --force-new-deployment
i=$(( i + 1 ))
done
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Troubleshooting AWS CodeBuild
Apache Maven builds reference artifacts from the wrong repository. Issue: When you use Maven with an AWS CodeBuild-provided Java build environment, ...
Read more >git - AWS CodePipeline, build failed & getting error as ...
The YAML file being referenced is the buildspec.yml file required by CodeBuild. More information can be found at ...
Read more >All the AWS CodeBuild You Can Stomach in 45 Minutes
GitHub project: https://github.com/krimple/ptw-2020- codebuild -sample (slides are in the presentation-slides.pdf file).OK, let's face it.
Read more >Fixed a Strange Error 'script.sh: 4: Login: not found' in AWS ...
Used AWS CodeBuild to build docker image and upload into elastic container registry, got an error '/codebuild/output/tmp/script.sh: 4: ...
Read more >How-to: debug and trace problems in AWS CodeBuild
Remark: the CodeBuild policy mentioned above only needs S3 permissions if using Amazon S3 to store your logs. In case it's missing you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @ookangzheng ,
change
Project
toPipelineProject
in your code, and everything will work again.Thanks, Adam
Actually I realized that I split CDK and my code into 2 different separate Github Repositories. While I use
codebuild.BuildSpec. fromSourceFilename('buildspec.yml')
, I have to putbuildspec.yml
under my code repo.