项目作者: alfssobsd

项目描述 :
Server for integration Jenkins CI and Gitlab CE
高级语言: Python
项目地址: git://github.com/alfssobsd/jenkins-gitlab-integrator.git
创建时间: 2017-07-18T10:36:58Z
项目社区:https://github.com/alfssobsd/jenkins-gitlab-integrator

开源协议:Apache License 2.0

下载


jenkins-gitlab-integrator

Server for integration GitLab CE with Jenkins (in last version GitLab (9.x) integration with jenkins enable only in EE version).

Server works only with multibranch pipeline jobs (maybe i will implement non-multibranch pipeline)

How it work:

  • every push starts build in jenkins (if the branch does not already exist, then the server will try to start the job until it reaches the limit of attempts or build starts.)
  • for each merge request server checks the build and write comment about status

Menu:

Usage" class="reference-link"> Usage

Install requirements libs" class="reference-link"> Install requirements libs

  1. pip install -r requirements.txt

Configure database schema" class="reference-link"> Configure database schema

Edit alembic.ini , set sqlalchemy.url for connect database

Run migrations alembic upgrade head

  1. vim alembic.ini
  2. alembic upgrade head

Configure server" class="reference-link"> Configure server

config:

  1. host: 0.0.0.0 # listen address
  2. port: 8000 # listen port
  3. log_level: INFO # log level
  4. server_url: http://jenkins-gitlab-integrator.example.local:8000 #server url for gitlab webhooks (need for auto create webhooks)
  5. gitlab_webhook_token: adEleRYsiViB1_34 #token for auth gitlab webhooks (Secret Token, Private-Token header)
  6. #generate secret
  7. #from cryptography.fernet import Fernet
  8. #Fernet.generate_key()
  9. session_secret: N5I6xGINvJ6RigIwd_SX7nHM4J7zYc6ONx6MGH3F__o= # salt for cookies
  10. #user list
  11. users:
  12. - username: root
  13. password: root
  14. permission: [ADMIN_UI]
  15. #mysql connection, same as alembic.ini
  16. mysql:
  17. db: jenkins_integrator
  18. host: 127.0.0.1
  19. user: root
  20. password: test
  21. port: 3306
  22. minsize: 5
  23. maxsize: 5
  24. #gitlab api config
  25. gitlab:
  26. url: https://gitlab.example.local #gitlab url
  27. access_token: adEleRYsiViB #gitlab user api token (look to gitlab docs)
  28. #background workers config
  29. workers:
  30. enable: yes #enable or disable run workers
  31. max_attempts: 1400 # how many try for do task
  32. scan_timeout: 60 # period between task run
  33. jenkins: #settings for jenkins
  34. user_id: sergei.kravchuk #jenkins user
  35. api_token: 2342b01c03caaa0465d144e310893ba9 # jenkins api token

Exec server" class="reference-link"> Exec server

Copy config to anower dirs and modify

  1. cp config/alembic.yml /opt/jenkins-gitlab-integrator/config/
  2. cp config/server.yml /opt/jenkins-gitlab-integrator/config/

Run migrations

  1. docker run --rm -v /opt/jenkins-gitlab-integrator/config:/opt/app/config -it alfss/jenkins-gitlab-integrator:latest migrate

Init example data

  1. docker run --rm -v /opt/jenkins-gitlab-integrator/config:/opt/app/config -it alfss/jenkins-gitlab-integrator:latest init_example_data

Start server

  1. docker run -d -v /opt/jenkins-gitlab-integrator/config:/opt/app/config alfss/jenkins-gitlab-integrator:latest

Or you can make docker image with your config in /opt/app/config

Admin UI" class="reference-link"> Admin UI

Admin UI provide:

  • management for delayed tasks
  • show current config & version
  • manage jenkins groups (webhooks)
  1. Go to http://server:port/

ui example

App stats" class="reference-link"> App stats

http://server:port/api/v1/stats return json with stats.

  1. {
  2. "coroutines_run": 2, # current execute coroutines
  3. "task_in_queue": 0, # count task with status new
  4. "app_version": "1.0.0",
  5. "server_url": "http://jenkins-gitlab-integrator.example.local:8000"
  6. }

Development" class="reference-link"> Development

Prepared dev machine" class="reference-link"> Prepared dev machine

  1. apt-get install -y python3-dev python3 python3-venv
  2. #init sandbox
  3. python3 -m venv ~/py-sandbox/py3/server-jenkins-notify-py3
  4. #use sandbox
  5. source ~/py-sandbox/py3/server-jenkins-notify-py3/bin/activate
  6. #install requirements
  7. pip install -r requirements.txt

Prepare DB" class="reference-link"> Prepare DB

  1. #create database
  2. create database jenkins_integrator DEFAULT CHARACTER SET utf8;
  3. vim alembic.ini
  4. alembic -c config/alembic.ini upgrade head

Build UI

  1. cd angular-admin-ui
  2. ng build --watch -d /static/

Run server

  1. python -m server.main -c /path/to/config/server.yml

Run test

  1. make test

Libs" class="reference-link"> Libs

Python Libs

UI Libs

Gitlab webhook processing" class="reference-link"> Gitlab webhook processing

Push processing

push processing

Mege processing

merge processing

Thanks" class="reference-link"> Thanks