Erdal Dogan
Erdal Dogan

Reputation: 617

How to trigger certain scripts when a commit occurs in the Gitlab repository

I am looking for a way to run some python scripts in our remote server when a commit occurs to our Gitlab repo. We are not hosting our repo, it is on Gitlab servers. Any recommendations are welcome.

Thanks in advance.

Upvotes: 1

Views: 1120

Answers (1)

Steve E.
Steve E.

Reputation: 9353

This can be solved by sending a request to your remote server as part of the Pipeline.

For example in your .gitlab-ci.yml file which exists in the root of the repository:

----

stages:
  - remote

sendRemote:
  stage: remote
  script: |
    curl -X POST \
      -F token=__SOME_TOKEN__ \
      -F "ref=$CI_COMMIT_REF_NAME" \
      https://remote.server.com

This would make a HTTPS POST request using Curl to your remote server. The use of a token __SOME_TOKEN__ provides some assurance that the request has come from Gitlab CI and not any other source. Other mechanisms for that purpose also exist, this is just one simple example.

In this example, the branch of the repository that was committed to is also included. There is an extensive list of other variables in the documentation.

Upvotes: 2

Related Questions