jenkins 集成 redmine 账户验证的方案

对于大部分开发团队来说,一般都需要一套 SCM 系统,通常是 svn + redmine,有些还会有 禅道之类的。

大家当然不希望上三套系统就有三套账号密码,那样记忆起来太麻烦了,所以大家都希望有统一的验证方案,当然,LDAP 是一种选择,考虑到它部署起来比较难,成本比较高,一般会选择统一使用其中某一个系统的账户验证。

redmine-auth

redmine-auth 利用了 apache2 中提供的 AuthProvider 特性和 mod_wsgi WSGIAuthUserScript 特性,编写了一个读取 redmine 账户信息的脚本,实现账户验证。

得益于 redmine-auth 使用了 sqlalchemy(从 0.2 版本开始),只要 sqlalchemy 支持的数据库,redmine-auth 都可以读取。所以无论 redmine 使用的是 MySQL 还是 postgresql,甚至是 oracle/mssql/sqlite,都可以无缝地使用 redmine-auth 进行账户验证。

安装

很简单,运行使用:

sudo pip install -U redmine-auth  

它会自动安装依赖的程序库,但是数据库驱动需要你手动安装,比如 MySQLdb 需要你自行安装好。

安装MySQLdb 

更新ruby版本

brew upgrade ruby

  安装msyql

brew install mysql

解决mysql_config not found错误

 修改OS X环境变量:打开终端,在终端中使用vim打开“~/.bash_profile”。在.bash_profile中添加以下内容:

PATH="/usr/local/mysql/bin:${PATH}"
export PATH
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export VERSIONER_PYTHON_PREFER_64_BIT=no
export VERSIONER_PYTHON_PREFER_32_BIT=yes

  

好了,到这里,MySQL-python包应该基本顺利安装。

 解决 Reason: image not found 错误

  安装完MySQL-python包后,让我们import MySQLdb,此时出现一个错误,错误最后一行写着 Reason: image not found。

  解决方法是在终端执行:

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

  

  错误:

clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

  mac os的Xcode从5.1起给编译器规定对于未知参数传入视为error,我们需要使用ARCHFLAGS将该error降级为warning,因此最后的安装命令应该如下:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py build

  

配置

方式一:

首先,进入 jenkins 的 Configure Global Security 页面,确保选择了“启用安全”,然后在“访问控制”-> “安全域” 那里选择“Authenticat via custom script”(需要安装Security Realm by custom script插件以后才有),最后,在 login command 输入框中填入以下内容:

redmine-auth-jenkins --conn-str=连接字符串

其中“连接字符串”是一个符合 SQLAlchemy 连接字符串定义的字符串,如:

mysql://user:pswd@localhost/redmine

怎么构造你自己的连接字符串,请参考 SQLAlchemy 的文档(http://docs.sqlalchemy.org/en/rel_0_8/core/engines.html#sqlalchemy.create_engine)。简单摘抄最关键的一句放在下面:

The string form of the URL is dialect+driver://user:password@host/dbname[?key=value..], where dialect is a database name such as mysql, oracle, postgresql, etc., and driver the name of a DBAPI, such as psycopg2, pyodbc, cx_oracle, etc. Alternatively, the URL can be an instance of URL.

 方式二:

首先,进入 jenkins 的 Configure Global Security 页面,确保选择了“启用安全”,然后在“访问控制”-> “安全域” 那里选择“ Redmine User Auth”(需要安装 Redmine plugin 插件以后才有),最后,在 login command 输入框中填入以下内容:

其它

redmine-auth 是一个 MIT 授权的开源项目,主页:https://github.com/laiyonghao/redmine-auth

原文地址:https://www.cnblogs.com/YatHo/p/7904977.html