Akria
Akria

Reputation: 43

Trigger Gitlab-ci from aws lambda

Im looking for lambda that can trigger Gitlab-ci pipeline to deploy specific branches and send results to slack.

Thx.

Upvotes: 3

Views: 2469

Answers (1)

Yasen
Yasen

Reputation: 4504

Trigger a pipeline

As per 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.

Watching a pipeline

To check pipeline results, use 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.

To check jobs status, use: Get a single pipeline or List project pipelines API calls.

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

Inform on Slack

To send Slack notifications with lambda, use this tutorial:

Creating an AWS Lambda Function and API Endpoint | Slack

Two cents about endpoint security

CI Trigger is secured by token. In general, it's enough for securing your endpoints.

But, if the approach isn't enough, there are some techniques to "hide" endpoints:

Upvotes: 1

Related Questions