I am attempting to define a CodePipeline V2 in Sceptre that will be triggered if specific files are modified.
By default, all files will trigger the pipeline
Parameters:
FileIncludes:
Type: 'CommaDelimitedList'
Default: '*'
CodePipeline:
Type: 'AWS::CodePipeline::Pipeline'
Properties:
Name: !Join ['-', ['mrt_pipeline', !Select [1, !Split ['/', !Ref RepositoryName]], 'OnDemand']]
PipelineType: 'V2'
ExecutionMode: QUEUED
RoleArn: {{sceptre_user_data.CodePipelineRoleArn}}
Variables:
- Name: foo
ArtifactStore:
# CloudFormation only supports S3 at the moment!
Type: 'S3'
Location: {{sceptre_user_data.S3ArtifactBucketId}}
Stages:
- Name: 'Source'
Actions:
- Name: 'Source'
RunOrder: 1
ActionTypeId:
Category: 'Source'
Owner: 'AWS'
Provider: 'CodeStarSourceConnection'
Version: '1'
# See: https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodestarConnectionSource.html
# for info on tying CodeBuild in
Configuration:
ConnectionArn: {{sceptre_user_data.CodeStarConnectionArn}}
FullRepositoryId: !Ref RepositoryName
BranchName: !Ref BranchToMonitor
OutputArtifactFormat: 'CODEBUILD_CLONE_REF'
OutputArtifacts:
- Name: 'SourceArtifact'
- Name: 'Build'
Actions:
- Name: 'Build'
RunOrder: 2
InputArtifacts:
- Name: 'SourceArtifact'
ActionTypeId:
Category: 'Build'
Owner: 'AWS'
Provider: 'CodeBuild'
Version: '1'
Configuration:
ProjectName: {{sceptre_user_data.CodeBuildProjectName}}
OutputArtifacts:
- Name: 'BuildArtifact'
Triggers:
- ProviderType: CodeStarSourceConnection
GitConfiguration:
Push:
- Branches:
Includes:
- !Ref BranchToMonitor
- FilePaths:
Includes: !Ref FileIncludes
SourceActionName: 'Source'
parameters:
RepositoryName: '...'
BranchToMonitor: 'main'
FileIncludes: 'manifest/**,design/aws-build/**'
When my pipleline is created, I end up with 2 filters
The first filter is causing the build to always run.
I can delete the first filter in the console, but it gets re-created if I make a change to my sceptre config.
The solution does not seem ideal, but it does solve my issue by eliminating the unwanted trigger from my pipeline definition.
The jq command finds the push
trigger that does not contain filePaths
and eliminates it.
parameters:
RepositoryName: '...'
BranchToMonitor: 'main'
FileIncludes: 'manifest/**,design/aws-build/**'
hooks:
after_launch:
- !cmd aws codepipeline get-pipeline --name my-pipeline-name > /tmp/pipeline.json
- !cmd cat /tmp/pipeline.json | jq "del(.metadata)|del(.pipeline.triggers[].gitConfiguration.push[]|select(.filePaths|not))" > /tmp/pipeline.out.json
- !cmd aws codepipeline update-pipeline --cli-input-json file:///tmp/pipeline.out.json --no-cli-pager