By using AWS re:Post, you agree to the Terms of Use

Pipeline trigger on pull request

0

Hello, Any one know how to trigger automatically pipeline on pull request so that it analyses the source branch before merging? Such as merge request pipeline on Gitlab. Repo is in codeCommit. Thanks

asked 7 months ago363 views
2 Answers
0

Triggers for codecommit are created/controlled through cloudwatch events. The source for the event can be specific target branch on a Pull Request.

Example - sorry about identing

{
   "source": [
   "aws.codecommit"
   ],
  "detail-type": [
  "CodeCommit Pull Request State Change"
  ],
  "resources": [
  "arn:aws:codecommit:us-west-2:80398EXAMPLE:MyTestRepo"
 ],
 "detail": {
   "event": [
      "pullRequestCreated",
     "pullRequestStatusChanged"
   ],
   "destinationReference": [
      "refs/heads/main"
   ],
   "pullRequestStatus": [
        "Open"
   ]
}
}

You can natively trigger codepipeline but if you wanted to trigger gitlab you would need to set the cloudwatch event to target a lambda which made the appropriate api call (and credentials) to trigger your gitlab pipeline

EXPERT
answered 7 months ago
  • Hi Peter , thanks for your answer! I tried but it’s still running pipeline from the destination branch. Maybe my question was unclear. Let me explain : My branch is develop. I make some changes in another branch ( feature) and want to merge feature and develop. What I want is the pipeline to run feature and not develop. So when I open a pull request in codecommit it will run automatically the source branch feature. I tried the code you gave me but it’s running the code from develop branch.

0

Hi Zale,

Please check in cloudwatch events-> rules or eventbridge rules ( both point to the same info ) . Here should be a rule that looks similar like this .

{
  "source": [
    "aws.codecommit"
  ],
  "detail-type": [
    "CodeCommit Repository State Change"
  ],
  "resources": [
    "arn:aws:codecommit:us-west-2:123456789012:CodeCommit"
  ],
  "detail": {
    "event": [
      "referenceCreated",
      "referenceUpdated"
    ],
    "referenceType": [
      "branch"
    ],
    "referenceName": [
      "main"
    ]
  }
}

change the referenceName to the branch you want to use to trigger the codepipeline. If you want to filter not by "feature" , more on a feature pattern like "feature-123" , "feature-124" then try to use filtering on event patterns. Please check this link : https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-content-based-filtering.html

Please write back if you need more info or if this was helpful.

answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions