logo
down
shadow

How to set CodeCommit repo branch name in CodeBuild project, during CI


How to set CodeCommit repo branch name in CodeBuild project, during CI

Content Index :

How to set CodeCommit repo branch name in CodeBuild project, during CI
Tag : git , By : Mikael
Date : November 29 2020, 04:01 AM

fixed the issue. Will look into that further You will need to set sourceVersion in StartBuild to select the desired branch.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Failing to push change from AWS CodeBuild to AWS CodeCommit


Tag : git , By : RinKaMan
Date : March 29 2020, 07:55 AM
To fix the issue you can do I don't think this was caused by permission. Can you try creating a standalone CodeBuild project with CodeCommit repo and running a build?
Check this thread https://forums.aws.amazon.com/thread.jspa?threadID=251732

Trouble cloning a codecommit repository to Codebuild with ssh


Tag : git , By : Barry
Date : March 29 2020, 07:55 AM
should help you out I've fixed the problem by adding sleep 10 before the interact in the expect script. I think the clone process didn't completely finish when the expect script ended and Codebuild continued to run regardless. Adding the pause allows the clone to finish.

AWS CodeBuild pipeline CodeCommit git repo path


Tag : amazon-web-services , By : somebody
Date : March 29 2020, 07:55 AM
This might help you Use the predefined environment variable "CODEBUILD_SRC_DIR". Details: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

AWS CodeBuild and CodeCommit repo as npm dependency


Tag : amazon-web-services , By : user179863
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I ran into this same issue today and got it working by enabling git-credential-helper in the env section of the buildspec file.
Example:
version: 0.2
env:
  git-credential-helper: yes
phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - npm install
  build:
    commands:
      - npm run build

How to trigger AWS Codebuild When Creating Pull Request in CodeCommit?


Tag : development , By : Thomas Plunkett
Date : March 29 2020, 07:55 AM
This might help you Ok, there is more than one year that the first response was posted on this thread and probably at the time that was the correct answer. But today it not correct anymore.
CodeCommit integrates with CloudWatch Events. It can signal an event when:
{
    "AWSTemplateFormatVersion": "2010-09-09",
        "Description": "Cloud Formation Template for Pipeline/Build/Deploy StaticWebSite on S3",

        "Parameters" : {

            "S3BucketForWebSite" : {
                "Type" : "String",
                "Description" : "The S3 address of Stack Resources and Files"
            }
        },

        "Resources": {

            "S3BucketForArtifacts" : {
                "Type" : "AWS::S3::Bucket",
                "Properties" : {
                  "AccessControl" : "Private"
                }
            },

            "CodeRepository" : {
                "Type" : "AWS::CodeCommit::Repository",
                "Properties" : {
                    "RepositoryName" : { "Fn::Sub": [ "${Stack}-Repo", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                    "RepositoryDescription" : "Repository for S3 Static Web Site"
                }
            },

            "BuildRole" : {
                "Type": "AWS::IAM::Role",
                "Properties": {
                    "RoleName": { "Fn::Sub": [ "${Stack}-CodeBuildExecRole", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                    "AssumeRolePolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [{ "Effect": "Allow", "Principal": {"Service": ["codebuild.amazonaws.com"]}, "Action": ["sts:AssumeRole"] }]
                    },
                    "Path": "/",
                    "Policies": [ {
                        "PolicyName": "root",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Sid": "WriteOnWebSiteBucket",
                                    "Action": ["s3:*"],
                                    "Resource": [
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}", { "BucketName": {"Ref" : "S3BucketForWebSite" }} ]},
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}/*", { "BucketName": {"Ref" : "S3BucketForWebSite" }} ]}
                                    ],
                                    "Effect": "Allow"
                                },
                                {
                                    "Sid": "CreateLogGroups",
                                    "Effect": "Allow",
                                    "Action": ["logs:CreateLogGroup"],
                                    "Resource": ["*"]
                                },
                                {
                                    "Sid": "CreateStreamAndPutLogs",
                                    "Effect": "Allow",
                                    "Action": ["logs:CreateLogStream", "logs:PutLogEvents"],
                                    "Resource": ["arn:aws:logs:*"]
                                },
                                {
                                    "Sid": "CheckBuketsInS3",
                                    "Effect": "Allow",
                                    "Action": ["s3:ListAllMyBuckets", "s3:HeadBucket"],
                                    "Resource": ["*"]
                                },
                                {
                                    "Sid": "GetAndPutObjectsInS3ArtifactStore",
                                    "Effect": "Allow",
                                    "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject", "s3:GetObjectVersion", "s3:GetBucketAcl", "s3:PutBucketAcl", "s3:PutObjectAcl", "s3:GetObjectVersion"],
                                    "Resource": [
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}", { "BucketName": {"Ref" : "S3BucketForArtifacts" }} ]},
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}/*", { "BucketName": {"Ref" : "S3BucketForArtifacts" }} ]}
                                    ]
                                }
                            ]
                        }
                    } ]
                }
            },

            "CodeBuild" : {
                "Type" : "AWS::CodeBuild::Project",
                "Properties" : {
                    "Artifacts" : {
                            "Type": "CODEPIPELINE",
                            "Name": { "Fn::Sub": [ "${Stack}-Build", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                            "Packaging": "NONE"
                        },
                    "BadgeEnabled" : false,
                    "Cache" : {"Type": "NO_CACHE"},
                    "Description" : { "Fn::Sub": [ "StaticWebSite Build for ${Stack}", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                    "Environment" : {
                        "Type": "LINUX_CONTAINER",
                        "Image": "aws/codebuild/nodejs:10.1.0",
                        "ComputeType": "BUILD_GENERAL1_SMALL",
                        "EnvironmentVariables": [],
                        "PrivilegedMode": false
                    },
                    "Name" : {"Ref" : "AWS::StackName" },
                    "ServiceRole" : { "Fn::GetAtt" : ["BuildRole", "Arn"] },
                    "Source" : {
                        "Type": "CODEPIPELINE",
                        "InsecureSsl": false
                    },
                    "TimeoutInMinutes" : 60
                }
            },

            "PipelineRole": {
               "Type": "AWS::IAM::Role",
               "Properties": {
                    "RoleName": { "Fn::Sub": [ "${Stack}-CodePipeLineExecRole", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                    "AssumeRolePolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [{ "Effect": "Allow", "Principal": {"Service": ["codepipeline.amazonaws.com"]}, "Action": ["sts:AssumeRole"] }]
                    },
                    "Path": "/",
                    "Policies": [ {
                        "PolicyName": "root",
                        "PolicyDocument": {
                            "Version": "2012-10-17",
                            "Statement": [
                                {
                                    "Sid": "WriteOnWebSiteBucket",
                                    "Action": ["s3:*"],
                                    "Resource": [
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}", { "BucketName": {"Ref" : "S3BucketForWebSite" }} ]},
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}/*", { "BucketName": {"Ref" : "S3BucketForWebSite" }} ]}
                                    ],
                                    "Effect": "Allow"
                                },
                                {
                                    "Sid": "InterfaceWithBucketsInS3",
                                    "Action": ["s3:GetObject", "s3:GetObjectVersion", "s3:GetBucketVersioning"],
                                    "Resource": "*",
                                    "Effect": "Allow"
                                },
                                {
                                    "Sid": "InterfaceWithArtifactStoreInS3",
                                    "Effect": "Allow",
                                    "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject", "s3:GetObjectVersion", "s3:GetBucketAcl", "s3:PutBucketAcl", "s3:PutObjectAcl", "s3:GetObjectVersion"],
                                    "Resource": [
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}", { "BucketName": {"Ref" : "S3BucketForArtifacts" }} ]},
                                        { "Fn::Sub": [ "arn:aws:s3:::${BucketName}/*", { "BucketName": {"Ref" : "S3BucketForArtifacts" }} ]}
                                    ]
                                },
                                {
                                    "Sid": "InterfaceWithCodeCommit",
                                    "Action": ["codecommit:CancelUploadArchive", "codecommit:GetBranch", "codecommit:GetCommit", "codecommit:GetUploadArchiveStatus", "codecommit:UploadArchive"],
                                    "Resource": "*",
                                    "Effect": "Allow"
                                },
                                {
                                    "Sid": "InterfaceWithCodeBuild",
                                    "Action": ["codebuild:BatchGetBuilds", "codebuild:StartBuild"],
                                    "Resource": "*",
                                    "Effect": "Allow"
                                }
                            ]
                        }            
                    } ]
               }
            },

            "CodePipeline" : {
                "Type" : "AWS::CodePipeline::Pipeline",
                "Properties" : {
                  "ArtifactStore" : {
                    "Location" : {"Ref": "S3BucketForArtifacts"},
                    "Type" : "S3"
                  },
                  "RestartExecutionOnUpdate" : false,
                  "RoleArn" : { "Fn::GetAtt" : ["PipelineRole", "Arn"] },
                  "Stages" : [
                    {
                        "Name": "Source",
                        "Actions": [
                            {
                                "Name": "Source",
                                "ActionTypeId": {"Category": "Source", "Owner": "AWS", "Provider": "CodeCommit", "Version": "1"},
                                "RunOrder": 1,
                                "Configuration": { "BranchName": "master", "PollForSourceChanges": "false", "RepositoryName": { "Fn::Sub": [ "${Stack}-Repo", { "Stack": {"Ref" : "AWS::StackName" }} ]}},
                                "OutputArtifacts": [ { "Name" : {"Ref" : "AWS::StackName"} } ],
                                "InputArtifacts": []
                            }
                        ]
                    },

                    {
                        "Name": "Build",
                        "Actions": [
                            {
                                "Name": "CodeBuild",
                                "ActionTypeId": { "Category": "Build", "Owner": "AWS", "Provider": "CodeBuild", "Version": "1" },
                                "RunOrder": 1,
                                "Configuration": { "ProjectName": {"Ref" : "AWS::StackName" } },
                                "InputArtifacts": [ { "Name" : {"Ref" : "AWS::StackName"} } ],
                                "OutputArtifacts": [ { "Name": { "Fn::Sub": [ "${Stack}-builded", { "Stack": {"Ref" : "AWS::StackName" }} ]} } ]
                            }
                        ]
                    }

                ]
                }
            },

            "CloudWathEventRole": {

                "Type": "AWS::IAM::Role",
                "Properties": {
                     "RoleName": { "Fn::Sub": [ "${Stack}-CloudWatchEventRole", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                     "AssumeRolePolicyDocument": {
                         "Version": "2012-10-17",
                         "Statement": [{ "Effect": "Allow", "Principal": {"Service": ["events.amazonaws.com"]}, "Action": ["sts:AssumeRole"] }]
                     },
                     "Path": "/",
                     "Policies": [ {
                         "PolicyName": "root",
                         "PolicyDocument": {
                             "Version": "2012-10-17",
                             "Statement": [
                                 {
                                     "Action": ["codepipeline:StartPipelineExecution"],
                                     "Resource": { "Fn::Sub": [ "arn:aws:codepipeline:${Region}:${Account}:${PipelineName}", { "Region": { "Ref" : "AWS::Region" }, "Account": { "Ref" : "AWS::AccountId" }, "PipelineName": {"Ref" : "CodePipeline" }} ]},
                                     "Effect": "Allow"
                                 }
                             ]
                         }            
                     } ]
                }

            },

            "CloudWatchEventRule" : {
                "Type" : "AWS::Events::Rule",
                "Properties" : {

                    "Name" : { "Fn::Sub": [ "${Stack}-Repo-Changes", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                    "Description" : "Check CodeCommit Repo Changes",

                    "EventPattern" : {
                        "detail-type": ["CodeCommit Repository State Change"],
                        "source": ["aws.codecommit"],
                        "resources": [{ "Fn::GetAtt" : [ "CodeRepository", "Arn" ] }],
                        "detail": { "referenceType": ["branch"], "referenceName": ["master"]}
                    },

                    "Targets" : [ {
                            "Id" : "codepipeline",
                            "Arn" : { "Fn::Sub": [ "arn:aws:codepipeline:${Region}:${Account}:${PipelineName}", { "Region": { "Ref" : "AWS::Region" }, "Account": { "Ref" : "AWS::AccountId" }, "PipelineName": {"Ref" : "CodePipeline" }} ]},
                            "RoleArn" : { "Fn::GetAtt" : ["CloudWathEventRole", "Arn"] }
                    } ]

                }
            }

        },

        "Outputs": {
            "RepoName" : {
                "Value" : { "Fn::Sub": [ "${Stack}-Repo", { "Stack": {"Ref" : "AWS::StackName" }} ]},
                "Description" : "CodeCommit Repository Name",
                "Export" : {"Name" : {"Fn::Sub": "${AWS::StackName}-RepoName" }}
            },
            "RepoArn" : {
                "Value" : { "Fn::GetAtt" : [ "CodeRepository", "Arn" ] },
                "Description" : "CodeCommit Repository Arn",
                "Export" : {"Name" : {"Fn::Sub": "${AWS::StackName}-RepoArn" }}
            },
            "RepoCloneSSHUrl" : {
                "Value" : { "Fn::GetAtt" : [ "CodeRepository", "CloneUrlSsh" ] },
                "Description" : "CodeCommit Repository SSH Url to be cloned",
                "Export" : {"Name" : {"Fn::Sub": "${AWS::StackName}-RepoCloneSSHUrl" }}
            },
            "RepoCloneHttpUrl" : {
                "Value" : { "Fn::GetAtt" : [ "CodeRepository", "CloneUrlHttp" ] },
                "Description" : "CodeCommit Repository Http Url to be cloned",
                "Export" : {"Name" : {"Fn::Sub": "${AWS::StackName}-RepoCloneHttpUrl" }}
            }

        }
    }
Related Posts Related QUESTIONS :
  • Exclude submodule of a submodule
  • Server-side custom git merge driver on GitHub/Azure Repos
  • What is the difference between trunk and branch in Git?
  • Git and Bitbucket: unauthorized when pushing
  • Missing the + parameter in git push after git rebase
  • Heroku fails pushing to master branch
  • Git, how to list my recently changed files
  • Is there a way to have editorconfig settings apply in git automatically when using git add? (using WebStorm)
  • shortcut to show git diff with origin master when working on a different branch with intellij
  • git default parameter on push
  • why on git checkout it automatically adds changed files in my new branch
  • "This branch has conflicts that must be resolved" but it's already merged
  • "Does not appear to be a git repository" when trying to clone via SSH
  • Git rebase clarifications
  • Abusing Git for implementation of Event Store architecture?
  • Delete multiple branches in a single run
  • GitLab - Determine if branch is protected from terminal git command
  • Azure DevOps: Set Git branch permission for all repos in all projects
  • How to check whether a file is updated after git pull?
  • How can one in Visual Studio open another GIT-branch without need to commit changes to the current one?
  • How to pull a branch which is being created from another branch in GIT
  • Adding 'git help' for alias commands?
  • How do I show tags in a custom git log format?
  • Why does git fetch origin master:master fast forward the local branch?
  • Can I edit the main.workflow github-actions file locally?
  • In Git, how to create a branch after resolving conflicts?
  • How to unsquash pushed commit to bitbucket
  • How can I git push to aws cloud9?
  • Prevent branches from being deleted on PR completion
  • Is there a git command to beautify the output of git diff between two branches?
  • git branch workflow policy
  • Git log, show only entries since last pull
  • Git can't check out on Linux with LF a file that was stored with CRLF
  • Git: Is branching per each feature really different from working all together on the same branch?
  • How do I limit what I pull down for my gatsby site from my repo?
  • Picking only range of commits while merging into another branch in git
  • How to get all the user commits from a Bitbucket repository?
  • Checking which file in two branches has a later commit
  • How do I avoid typing "git" at the begining of every Git command?
  • Visual Studio 2019 Github extension commands: "pop and restore staged" vs "pop all as unstaged"?
  • Last non-merge commit author for a list of branches
  • How undone a repo and convert it as a regular directory
  • Commit cmake autogen makefiles/project files to git repo
  • GIT: Make 2 revisions become a single revision instead of 2 revisions
  • Is there any way to achieve Graph by Branch feature through git log?
  • How do you switch between branches in VSCode with GIT?
  • Github pushing commits to different folder structure
  • How do I close a branch i accidentally reopened?
  • "abort: No module named selectors!" when Pushing Mercurial repository to Git repository
  • Git force commit and push , when getting "nothing to commit"
  • GIT - Keeps asking username even after global storage
  • How to clone a single specific file from Bitbucket
  • How can I revert this command "git status --porcelain | grep '^??' | cut -c4- >> .gitignore"?
  • Git strategy for when you need to work on several features at a time
  • What is preventing me from using $_ in a pipeline?
  • Commit pushed with 2 authors
  • Create an intermediary commit in history
  • Git move directory from one branch to another within the same repository while preserving history?
  • Export git history, for a file and a subfolder, into another existing git repo?
  • git diff ignore semicolon at end of line
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com