Gitlab CI集成工具的應用

Gitlab CI集成工具的應用

什麼是Gitlab CI工具

Continuous Integration is a software development practice in which you build and test software every time a developer pushes code to the application, and it happens several times a day.

持續集成是一種軟件開發實踐,它可以在每次開發人員將代碼推送到應用程序時構建和測試軟件,並且這種情況每天都可能發生幾次。

Gitlab CI工具有什麼用

  • Unit test
  • Build software
  • Integration tests

我們使用Gitlab CI工具做什麼

  1. 自動判斷代碼coding style是否符合PEP8編碼格式(flake8)
  2. 自動執行單元測試,判斷流程代碼能否執行成功(pytest)

這樣每次將代碼上傳(PUSH)到gitlab上後,都會自動執行以上兩個步驟,只有以上兩個步驟通過後, 纔會開始後續的人工Code View操作

怎麼使用Gitlab CI工具

1. 在gitlab項目中集成CI工具

在項目中新增.gitlab-ci.yml文件,編寫測試步驟

test:
  script:
  - pip install virtualenv
  - yum install -y mysql-devel python-devel
  - virtualenv dobot-env
  - source dobot-env/bin/activate
  - pip install -r requirements.txt
  - pip install flake8
  - flake8 --exclude dobot-env
  - pytest

2. 在服務器上安裝gitlab-runner

sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
sudo chmod +x /usr/local/bin/gitlab-runner
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
/usr/local/bin/gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
/usr/local/bin/gitlab-runner start

3. 爲項目配置gitlab-runner

/usr/local/bin/gitlab-runner register

並輸入項目中給予的鏈接和授權碼

Reference

  1. continuous-integration-delivery-and-deployment-with-gitlab
  2. GitLab Continuous Integration (GitLab CI/CD)
  3. Install GitLab Runner manually on GNU/Linux
  4. Registering Runners
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章