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

Zale
已提问 2 年前2594 查看次数
2 回答
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

AWS
专家
Peter_G
已回答 2 年前
  • 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.

AWS
dan_m
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则