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

AWS CDK C# Is it possible to add BitBucket as a source action in the CodePipeline in the source stage? #6710

Closed
jefersonlopessage opened this issue Mar 13, 2020 · 0 comments · Fixed by #6756
Assignees
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline effort/small Small work item – less than a day of effort feature-request A feature should be added or improved.

Comments

@jefersonlopessage
Copy link

jefersonlopessage commented Mar 13, 2020

❓ General Issue

The Question

Hello, I'm trying to link BitBucket as a source in my CodePipeline using Aws CDK C #, but I'm not getting it and I didn't find any documentation related to this item.

Has anyone managed to implement this?

Below example of the code I am using.

Environment

  • CDK CLI Version: 1.27.0 (build a98c0b3)
  • Module Version:
  • OS: Windows 10
  • Language: csharp

Other information

public class CodePipelineStack : Stack
    {
        internal CodePipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            var name = "name";
            var environment = Util.GetEnvironment(this.Account);
            var branch = "develop";
            var repo = "repo";

            var role = new Role(this, $"{name}-build-role", new RoleProps
            {
                RoleName = $"{name}-build-role",
                AssumedBy = new ServicePrincipal("codebuild.amazonaws.com"),
                Description = $"This is a custom role ({name}-build-role)",
                InlinePolicies = new Dictionary<string, PolicyDocument>
                {
                    [$"{name}-code-build-role"] = Util.ecsServicePolicies.Where(p => p.Key == "code-build-role").Select(s => s.Value).FirstOrDefault()
                }
            });
            

            var build = new PipelineProject(this, $"{name}-build", new PipelineProjectProps
            {
                BuildSpec = BuildSpec.FromSourceFilename($"buildspec-{environment}"),
                Environment = new BuildEnvironment
                {
                    BuildImage = LinuxBuildImage.STANDARD_1_0,
                    Privileged = true,
                    ComputeType = ComputeType.SMALL
                },
                Description = "Build Description",
                ProjectName = $"buildspec-{environment}",
                Timeout = Duration.Minutes(15),
                EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
                {
                    ["ENVIRONMENT"] = new BuildEnvironmentVariable
                    {
                        Type = BuildEnvironmentVariableType.PLAINTEXT,
                        Value = environment
                    },
                    ["APP_NAME"] = new BuildEnvironmentVariable
                    {
                        Type = BuildEnvironmentVariableType.PLAINTEXT,
                        Value = name
                    }
                },
                Badge = false,
                Role = role,
                Cache = Cache.Bucket(new Bucket(this, $"{name}-build-cache",
                                        new BucketProps
                                        {
                                            Versioned = false,
                                            BucketName = $"{name}-build-cache",
                                            Encryption = BucketEncryption.KMS_MANAGED,
                                            RemovalPolicy = RemovalPolicy.DESTROY,
                                            BlockPublicAccess = new BlockPublicAccess(
                                                new BlockPublicAccessOptions
                                                {
                                                    BlockPublicAcls = true,
                                                    BlockPublicPolicy = true,
                                                    IgnorePublicAcls = true,
                                                    RestrictPublicBuckets = true
                                                }
                                            ),
                                            AccessControl = BucketAccessControl.BUCKET_OWNER_FULL_CONTROL,
                                            PublicReadAccess = false,
                                        }),
                                    new BucketCacheOptions
                                    {
                                        Prefix = environment
                                    })
            });

            var buildOutput = new Artifact_($"{name}-build-output");
            var sourceOutput = new Artifact_();

            var source = Amazon.CDK.AWS.CodeBuild.Source.BitBucket(new BitBucketSourceProps
            {
                BranchOrRef = "",
                CloneDepth = 0,
                Identifier = "",
                Owner = "",
                Repo = repo,
                ReportBuildStatus = true,
                Webhook = true,
                WebhookFilters = new[] {
                    FilterGroup.InEventOf(EventAction.PUSH).AndBranchIs(branch),
                    FilterGroup.InEventOf(EventAction.PULL_REQUEST_MERGED).AndBranchIs(branch),
                    FilterGroup.InEventOf(EventAction.PULL_REQUEST_UPDATED).AndBranchIs(branch),
                },
            });

            var pipeline = new Pipeline(this, $"{name}-pipeline", new PipelineProps
            {
                PipelineName = $"{name}-pipeline",
                RestartExecutionOnUpdate = true,
                Stages = new[]
                {
                    new StageProps
                    {
                        StageName = "Source",
                        Actions = new []
                        {
                            source // error in this line 
                        }
                    },
                    new StageProps
                    {
                        StageName = "Build",
                        Actions = new CodeBuildAction[]
                        {
                            new CodeBuildAction(new CodeBuildActionProps
                            {
                                ActionName = $"{name}-build",
                                Project = build,
                                Input = sourceOutput,
                                Outputs = new [] { buildOutput }
                            })
                        }
                    },
                }
            });
   }
    }
@jefersonlopessage jefersonlopessage added the needs-triage This issue or PR still needs to be triaged. label Mar 13, 2020
@SomayaB SomayaB added guidance Question that needs advice or information. language/dotnet Related to .NET bindings @aws-cdk/aws-codepipeline Related to AWS CodePipeline labels Mar 13, 2020
@skinny85 skinny85 added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. and removed guidance Question that needs advice or information. language/dotnet Related to .NET bindings needs-triage This issue or PR still needs to be triaged. labels Mar 13, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Mar 17, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Mar 19, 2020
@mergify mergify bot closed this as completed in #6756 Mar 19, 2020
mergify bot added a commit that referenced this issue Mar 19, 2020
… action (#6756)

Fixes #6710

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline effort/small Small work item – less than a day of effort feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants