Gitlab CI/CD
Let’s start use gitlab ci/cd in following steps:
First version is based on a simple hello world python project test-python:
webapp folder is the application
test.py is the unit test for application
deploy.sh is the deploy script
.gitlab-ci.yml is the gitlab ci/cd control file
When new checkin is pushed to gitlab, there will trigger the unit test for application and then deploy to environment (some vm in digtalocean). Then you will see the pipelines via:
Apparently this solution is not well structed.
Let’s separate the develop code from application code into two projects:
python-app is the project with application and simple unit test:
piplines result for python-app
python-ci is the project which will deploy the application to environment:
The environment for application will be visited via:
Tips:
When you need to trigger one project by another project, you need to add pipeline trigger by [settings]->[CI/CD] and click [Add trigger] under [pipeline trigger], then you will get trigger token:
When you trigger from another project, you will write some code like
- curl --request POST --form "token=$CI_TOKEN" --form ref=master https://gitlab.com/api/v4/projects/7458040/trigger/pipeline
the project id “7458040” will be get via [settings]->[general] and expand [Project general] tab: