从 aws lambda 触发 Gitlab-ci

Trigger Gitlab-ci from aws lambda

我正在寻找可以触发 Gitlab-ci 管道部署 specific 分支并将结果发送到 slack 的 lambda。

谢谢。

触发管道

根据GitLab Trigger API manual

To trigger a job you need to send a POST request to GitLab’s API endpoint:

    curl -X POST <API url>/projects/<your_awesome_gitlab_project>/trigger/pipeline

The required parameters are the trigger’s token and the Git ref on which the trigger will be performed. Valid refs are the branch and the tag. The :id of a project can be found by querying the API or by visiting the CI/CD settings page which provides self-explanatory examples.

观看管道

要检查管道结果,请使用 CloudWatch Events:

You can set up a rule to run an AWS Lambda function on a schedule. This tutorial shows how to use the AWS Management Console or the AWS CLI to create the rule. If you would like to use the AWS CLI but have not installed it, see the AWS Command Line Interface User Guide.

要检查作业状态,请使用:Get a single pipeline or List project pipelines API 调用。

curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/projects/1/pipelines/46"

通知Slack

要使用 lambda 发送 Slack 通知,请使用此教程:

Creating an AWS Lambda Function and API Endpoint | Slack

关于端点安全的两分钱

CI 触发器由 token 保护。通常,它足以保护您的端点。

但是,如果方法还不够,还有一些技术可以 "hide" 端点: