简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM