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

CodeBuild: directly connect with codeStarConnection #32443

Closed
2 tasks
vwits-sujit opened this issue Dec 9, 2024 · 4 comments
Closed
2 tasks

CodeBuild: directly connect with codeStarConnection #32443

vwits-sujit opened this issue Dec 9, 2024 · 4 comments
Assignees
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. feature-request A feature should be added or improved. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@vwits-sujit
Copy link

Describe the feature

Codebuild project have property called source it allowed to connect to github/bitbucket/codeCommit by passing token key, can't find anyway to connect external source using existing codeStar connection.

Use Case

When I try to add stage in codePipeline, which have different codebuild I am not able to connect with external source. codePipeline.connection does have option to connect with external source by using codestar connection arn, which is not compartible with ISource in codeBuild.

Proposed Solution

No response

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.172.0

Environment details (OS name and version, etc.)

ALL

@vwits-sujit vwits-sujit added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 9, 2024
@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Dec 9, 2024
@vwits-sujit vwits-sujit changed the title CodeBuild: directly connect with codeStarConnection instead CodeBuild: directly connect with codeStarConnection Dec 9, 2024
@nmussy
Copy link
Contributor

nmussy commented Dec 9, 2024

I'm not sure I've fully understood your issue, but does this example match your expectation?

import { Stack, type StackProps } from "aws-cdk-lib";
import type { Construct } from "constructs";
import { CfnConnection } from "aws-cdk-lib/aws-codestarconnections";
import { Artifact, Pipeline } from "aws-cdk-lib/aws-codepipeline";
import {
  CodeStarConnectionsSourceAction,
  CodeBuildAction,
} from "aws-cdk-lib/aws-codepipeline-actions";
import { PipelineProject } from "aws-cdk-lib/aws-codebuild";

export class TestStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    // You can also import the connectionArn from another stack
    const { attrConnectionArn: connectionArn } = new CfnConnection(
      this,
      "Connection",
      { connectionName: "connectionName" }
    );

    const sourceOutput = new Artifact();
    const sourceAction = new CodeStarConnectionsSourceAction({
      actionName: "ExampleConnection",
      owner: "nmussy",
      repo: "aws-cdk",
      branch: "main",
      output: sourceOutput,
      connectionArn,
    });

    const buildAction = new CodeBuildAction({
      actionName: "CodeBuild",
      project: new PipelineProject(this, "Project"),
      input: sourceOutput,
    });

    new Pipeline(this, "Pipeline", {
      stages: [
        { stageName: "Source", actions: [sourceAction] },
        { stageName: "Build", actions: [buildAction] },
      ],
    });
  }
}

@vwits-sujit
Copy link
Author

vwits-sujit commented Dec 9, 2024

connectionArn

Hi @nmussy

Above example work when i creating pipeline as you explain.

I am creating pipeline in different way. similar like below code. may be you can have a look.

`export class PipelineStack extends Stack{
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

    const pipelineSource  = CodePipelineSource.connection("owner/repo", "master", {
        connectionArn: "codeStarConnectionARN",
    })
    const pipeline = new CodePipeline(this, "TestPipeline", {
        pipelineName: "test-pipeline",
        selfMutation: true,
        codeBuildDefaults: {

            subnetSelection: {subnetType: SubnetType.PRIVATE_ISOLATED},
            rolePolicy: [
                new PolicyStatement({
                    resources: ['*'],
                    effect: Effect.ALLOW,
                    actions: ['kms:Decrypt', 'kms:Encrypt', 'kms:ReEncrypt*', 'kms:GenerateDataKey'],
                }),
            ],
            partialBuildSpec: BuildSpec.fromObject({
                phases: {
                    install: {
                        commands: [
                           "Some commands"
                        ],
                    },
                },
            }),
        },
        synth: new CodeBuildStep("Synth", {
                input: pipelineSource,
                // primaryOutputDirectory: 'infra/cdk.out',
                installCommands: [
                    "Some commands "

                ],
                commands: [
                    "Some Commands"
                ]
            }
        ),
    });

    pipeline.addStage(
        new Application(this, 'NewStuffBuildStage')
    )
}

}`

applicaton.ts
export class Application extends Stage{ constructor(scope:Construct, id:string, props?: StageProps){ super(scope, id); new StuffBuildStack(this, 'stuffBuildStack') } }

'stuffBuildStack.ts
export class StuffBuildStack extends Stack{

constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    new Project(this, 'stuff-build',{
        projectName: 'bscanner',
        role: new Role(this, 'stuff-role', {
            assumedBy: new ServicePrincipal('codebuild.amazonaws.com'),
        }),

//*****************************************
// source required instance of ISource, but can't find the way to provide Isource from CodePipelineSource
source: pipelineSource //as a props
buildSpec: BuildSpec.fromSourceFilename(path.resolve(__dirname, 'buildspec.yml')),
});
}

`

@khushail khushail 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 Dec 12, 2024
@khushail khushail self-assigned this Dec 12, 2024
@khushail khushail added the p2 label Dec 12, 2024
@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Dec 12, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. feature-request A feature should be added or improved. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants