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.
Related
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.
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.
Usecase
I want to extract the reason of why my codepipeline has been failed and send that information as an email. In the codepipeline console, i can see the below message under 'Latest action execution message` heading.
Is there any way i can able to extract this message using any Codepipeline API methods. Because i tested most the AWS cli codepipeline commands but didn't find this information.
Thanks
Any help is appreciated
CodePipeline's CloudWatch events include a pipeline execution id, which you can use to call ListActionExecutions. ListActionExecutions will give you the status for failed actions and will be stable over time.
GetPipelineState has the status for the latest pipeline execution in a given stage. It's possible for a pipeline execution to enter a stage after a failure and before you receive a CloudWatch event (so you observe the wrong pipeline execution).
You can setup an email notification using SNS, and then configure your pipeline to send alerts to the corresponding SNS topic.
You can read detailed steps in Tutorial: Set Up a CloudWatch Events Rule to Receive Email Notifications for Pipeline State Changes.
Since the default notification doesn't include the job failure message, you'll need to write a Lambda Function that receives the state change event object and calls the getPipelineState function to return the last failure message.
Notifications: https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-repository-email.html
Triggers: https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-notify.html
The official document states that for CodeCommit repository 'events which follow CloudWatch Event Rules' (like pull requests), we use Repository Notifications.
Whereas for CodeCommit repository events which are just 'operational events' (like creating branches, pushing code to a branch), we use Repository Triggers.
I don't understand the difference between 'events which follow CloudWatch Event Rules' and 'operational events'. For me, both pull requests and pushing code to branch seem similar events.
Thus, confused between why we need both Repository Notifications and Repository Triggers.
I have asked the same question today and I found this on docs:
Repository notifications are different from repository triggers. 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. They are more limited in scope. For more information about using triggers, see Manage Triggers for a Repository.
IMO, AWS documentation has not clearly stated the difference between notification and triggers and cloudwatch events. Here is my understanding :
Notifications should be used for literal notification and not for taking action based on them.
Triggers are supposed to initiate action. So, if I need to invoke some service based on this event on which trigger is based, I would do that and hence the option to integrate Lambda service. In a way to add automation after codecommit events.
However, Cloudwatch Events provide a wide variety of integration option for codecommit events which are not available with trigger.
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.