I have created a cloudwatch event which triggers a codebuild project when there is a push in the master branch of a codecommit repo. I am trying to build the project when there is a push in the "develop" branch. I can specify the source branch for triggering the build. However, codebuild is always building from the master branch.
I am looking for a way to send the source branch to codebuild when initiated by a cloudwatch event trigger.
This is my cloudwatch event.
It's of course a very old thread, but I found it when googling the same question, so maybe someone will find it useful:
To make CloudWatch trigger a build on the PR where you pushed, when specifying target chose “Input Transformer”. There in “input path” enter {"source-version":"$.detail.sourceReference"}.
In “Input Template” textbox enter {"sourceVersion": <source-version>}.
Worked for me.
Related
I have a monorepo containing several sub-projects (microservices) stored on GitHub. I am trying to build it using the combination of AWS CodePipeline and CodeBuild. I would like to start pipelines depending on what sub-project has been changed. For example, if a file in a service-1 folder is changed I want to run a service-1 pipeline, and I don't want to run build for service-2 or service-3.
In Google Cloud Build, there is a possibility to specify "included files" and "ignored files". I am trying to find exactly the same thing in AWS.
Quastion: How to specify files/folders changes to which would trigger a CodePipleine build?
Like with many services in AWS, you'd have to build this yourself. There is a blogpost on how to customize triggers. It roughly consists of the following:
Create a CW event rule that triggers a lambda on codecommit repo updates.
Write the logic that suits your usecase in the abovementioned lambda
The lambda eventually emits a custom CW event
Configure your pipelines to trigger based on the custom event payload
Article can be found at: https://aws.amazon.com/blogs/devops/adding-custom-logic-to-aws-codepipeline-with-aws-lambda-and-amazon-cloudwatch-events/
Background:
I'm planning on creating a Codepipeline that has multiple source actions within the initial source stage. Each source action is a GitHub repo that will have its own AWS CodePipeline webhook. Within the pipeline's next stage, I want to have an invoke action that will get the pipeline execution's webhook that triggered the pipeline run and set the input artifact for the downstream build stage to be the source action that is associated with the triggered webhook. For example, if repo A's webhook caused pipeline execution #1, then the invoke action will somehow identify that the repo A's webhook was the trigger and then pass repo A's output artifact to the downstream build stage.
Problem:
I haven't found a solution to get the Codepipeline webhook that triggered the pipeline run. Looking at the boto3 Codepipeline docs, the closest I've got was list_webhooks that identifies what pipeline the webhook is associated with but nothing in regards to if that webhook triggered Codepipeline execution ID 123.
The list_pipeline_executions command should help you in this case. It provides you with CodePipeline execution summaries, where the first result is the latest execution ID. Each summary has a trigger attribute with information about how the execution was triggered. For a webhook it looks like this:
"trigger": {
"triggerType": "Webhook",
"triggerDetail": "arn:aws:codepipeline:<region>:<account-id>:webhook:<webhook-id>"
}
If your pipeline is likely to be running concurrently, make sure you get the current execution ID first so things do not get mixed up. You can do this with a one-liner in CodeBuild as suggested here.
Well, I would like to avoid some types of commits to trigger an AWS CodePipeline, but I can't find any configuration about this in Source phase:
But, If AWS CodeBuild is not linked with AWS CodePipeline I have access to more features about trigger:
How can I configure trigger options using AWS CodePipeline ?
You can do this by editing the CloudWatch Event for the pipeline. Using a Lambda function, you can look for a specific type of change in your commit. The example in the link below looks for changes to specific files - so if you change the readme.md file, for example, don't deploy.
https://aws.amazon.com/blogs/devops/adding-custom-logic-to-aws-codepipeline-with-aws-lambda-and-amazon-cloudwatch-events/
You could take this example further and look for specific flags in your commit message, for example.
I want SNS when branch is deleted. What to use? CodeCommit Trigger or CodeCommit Notification?
Trigger can be activated with branch deletion and Notification can be activated by branch delete also. What to select and why? Help me understand.
Although you can use both triggers/notifications but point to note is Triggers do not use CloudWatch Events rules to evaluate repository events.
Refer - https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-repository-email.html
Although you can configure a trigger to use Amazon SNS to send emails
about some repository events, those events are limited to operational
events, such as creating branches and pushing code to a branch.
Triggers do not use CloudWatch Events rules to evaluate repository
events.
CodeCommit trigger
Choose trigger if you are interested in one specific branch (or few named branches; up to 10) being deleted.
CodeCommit Notification
Setup notification if you want to get notified about any branch in your repository being deleted.
AWS CodePipeline now supports GitHub WebHook, but by default
every time code is pushed(changed) on the master branch, CodePipeline is triggered.
However, I only want it to run when I actually publish a release.
So, I manually configured the auto-generated GitHub WebHook as follows:
(Uncheck Pushes, check Releases)
but after the configuration, CodePipeline is not kicked any more.
(When I check Pushes again, it starts watching every pushes again)
Does it only watch Pushes action?
If it does, is there any other way to kick CodePipeline by GitHub release actions?
CodePipeline's webhooks were designed to handle push events, but I think there's no reason why you shouldn't be able to configure the CodePipeline webhook to trigger on release events. No information from the webhook invocation is actually used as part of the source action, so you could trigger it from anything.
The reason it's not working is probably because of how your webhook filters are configured.
Take a look at the ListWebhooks API to see how your webhook is configured.
This page describes how the filters and authentication configuration is used to match github events to decide whether to trigger a pipeline execution or not.