Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pipelines: v2 multi-branch support #29704

Open
1 of 2 tasks
andreprawira opened this issue Apr 3, 2024 · 6 comments
Open
1 of 2 tasks

pipelines: v2 multi-branch support #29704

andreprawira opened this issue Apr 3, 2024 · 6 comments
Labels
@aws-cdk/pipelines CDK Pipelines library effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@andreprawira
Copy link

Describe the feature

AWS has released pipeline v2 that supports deployment based on multi-branch triggers. However it does not yet exist in AWS. The feature that i'm requesting should be added for this module. I already mentioned this in another issue but it was not supported yet and people suggested me to create a feature request.

Use Case

We need this feature because often times we have to automate creating pipelines for deployment based on multiple branches and at the moment we cant do that with CDK. We ended up either manually changing the pipeline branch (which is a no-no) or create however many pipelines for those branches.

Proposed Solution

from aws_cdk import (
    Stack,
    Environment,
    aws_codebuild as codebuild,
    aws_iam as iam,
    pipelines as pipelines,
    aws_codepipeline as codepipeline,
    aws_codepipeline_actions as codepipeline_actions,
)

        source_output = codepipeline.Artifact()
        l2_pipeline = codepipeline.Pipeline(
            self,
            "l2-codepipeline",
            pipeline_type=codepipeline.PipelineType.V2,
            pipeline_name="l2-cdk-pipeline",
            cross_account_keys=True,
            triggers=[
                codepipeline.TriggerProps(
                    provider_type=codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
                    git_configuration=codepipeline.GitConfiguration(
                        source_action=codepipeline_actions.CodeStarConnectionsSourceAction(
                            action_name="BitBucket_Source",
                            owner="Me",
                            repo="my-dummy-repo",
                            branch="main",
                            output=source_output,
                            connection_arn="my-dummy-codestar-connection-arn",
                        ),
                        push_filter=[
                            codepipeline.GitBranchFilter(
                                branch_includes=["main, feat/dns, chore/**"]
                            )
                        ],
                    ),
                )
            ],
        )

        # Define the pipeline
        pipeline = pipelines.CodePipeline(
            self,
            "l3-cdk-pipeline",
            code_pipeline=l2_pipeline,
            code_build_defaults=pipelines.CodeBuildOptions(
                build_environment=codebuild.BuildEnvironment(
                    build_image=codebuild.LinuxBuildImage.STANDARD_6_0,
                    privileged=True,
                    compute_type=codebuild.ComputeType.LARGE,
                ),
                partial_build_spec=codebuild.BuildSpec.from_object(
                    {
                        "env": {
                            "git-credential-helper": "yes",
                        }
                    }
                ),
            ),
            synth=pipelines.CodeBuildStep(
                "Synth",
                 input=pipelines.CodePipelineSource.connection(
                     repo_string="my-dummy-repo",
                     branch="main",
                     connection_arn="my-dummy-codestar-connection-arn",
                     code_build_clone_output=True,
                     trigger_on_push=True,
                 ),
                additional_inputs={
                    "ui-repository": pipelines.CodePipelineSource.connection(
                        repo_string="my-dummy-ui-repo",
                        branch="main",
                        connection_arn="my-dummy-codestar-connection-arn",
                        code_build_clone_output=True,
                        trigger_on_push=True,
                    ),
                },
                partial_build_spec=codebuild.BuildSpec.from_object(
                    {
                        "phases": {
                            "pre_build": {
                                "commands": [
                                    "ls -la",
                                ],
                            },
                        }
                    }
                ),
                commands=[
                    "npm install -g aws-cdk",
                    "pip install -r requirements.txt",
                    "npx cdk synth -c customer=$customer",
                ],
                env={"customer": props.infra.name},
                role_policy_statements=[
                    iam.PolicyStatement(
                        actions=["sts:AssumeRole"],
                        resources=["*"],
                        conditions={
                            "StringEquals": {
                                "iam:ResourceTag/aws-cdk:bootstrap-role": "lookup"
                            }
                        },
                    )
                ],
            ),
            self_mutation=True,
            use_change_sets=False,
            docker_enabled_for_synth=True,
            docker_enabled_for_self_mutation=True,
        )

maybe something like that

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.131.0 (build 92b912d)

Environment details (OS name and version, etc.)

Windows 10

@andreprawira andreprawira added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 3, 2024
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Apr 3, 2024
@andreprawira
Copy link
Author

@go-to-k @atali feature request created

@atali
Copy link

atali commented Apr 3, 2024

Can we also support triggers on the additional_inputs ?

@go-to-k
Copy link
Contributor

go-to-k commented Apr 3, 2024

Thanks for this issue.

The branch trigger in the codepipeline module will be up to the following PR and we should work after this is merged.
At that time, if anyone wants to work on this issue, it is welcome to do so. If no one is available, I may take it.

#29127

@tim-finnigan tim-finnigan self-assigned this Apr 3, 2024
@tim-finnigan tim-finnigan added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 3, 2024
@tim-finnigan
Copy link

Thanks for the feature request and for referencing the PR above. It looks like this issue also overlaps with #25946.

@tim-finnigan tim-finnigan added p2 effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Apr 3, 2024
@tim-finnigan tim-finnigan removed their assignment Apr 3, 2024
@andreprawira
Copy link
Author

@tim-finnigan @go-to-k any idea if the pipelines module (not the code_pipeline module) will ever get a pipeline v2 support? i know the support exists for code_pipeline module, but we have the bulk of our code using pipelines module already and prefer not to refactor the whole thing

@go-to-k
Copy link
Contributor

go-to-k commented Aug 1, 2024

@andreprawira
The PR for the V2 multi-branch triggers in the code_pipeleine module I mentioned above has been reverted and now another PR is underway. Depending on this PR, the way it is handled in the pipelines module will change, so we may not know anything yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

4 participants