我遇到的问题如下:
执行:
./cruise build test_cc_01
的时候,会出现以下错误?字面上看是连接SVN没权限,但我试过好多SVN,而且之前我已经通过./cruise add方法将SVN的代码拉下来过了,难道它不记得密码?
即便它不记得密码,我也试过./cruise build test_cc_01 --username zheng.cuizh --password PPPPPPP
也不行,
我还试过在test_cc_01项目的配置文件cruise_config.rb中,加入如下代码:
project.source_control.username = 'zheng.cuizh'
project.source_control.password = 'PPPPPPP'
还是不行!
执行时候所有的代码和错误提示如下:
hostname@ubuntu:~/ruby/cruisecontrolrb-1.3.0$ ./cruise build test_cc_01
cruise data root = '/home/hostname/.cruise'
Builder for project 'test_cc_01' started
Logging to: /home/hostname/ruby/cruisecontrolrb-1.3.0/log/test_cc_01_builder.log
Build loop failed
BuilderError: svn: OPTIONS of 'https://roadrunner.googlecode.com/svn/trunk': authorization failed (https://roadrunner.googlecode.com)
./script/../config/../lib/subversion.rb:161:in `execute_with_error_log'
./script/../config/../lib/command_line.rb:86:in `call'
./script/../config/../lib/command_line.rb:86:in `e'
./script/../config/../lib/command_line.rb:84:in `popen'
./script/../config/../lib/command_line.rb:84:in `e'
./script/../config/../lib/command_line.rb:71:in `execute'
./script/../config/../lib/command_line.rb:70:in `chdir'
./script/../config/../lib/command_line.rb:70:in `execute'
./script/../config/../lib/subversion.rb:152:in `execute_with_error_log'
./script/../config/../lib/subversion.rb:141:in `execute_in_local_copy'
./script/../config/../lib/subversion.rb:140:in `chdir'
./script/../config/../lib/subversion.rb:140:in `execute_in_local_copy'
./script/../config/../lib/subversion.rb:127:in `svn'
./script/../config/../lib/subversion.rb:112:in `log'
./script/../config/../lib/subversion.rb:62:in `latest_revision'
./script/../config/../app/models/project.rb:210:in `build_if_necessary'
./script/../config/../app/models/polling_scheduler.rb:13:in `run'
./script/builder:79
./script/builder:78:in `catch'
./script/builder:78
./cruise:14:in `load'
./cruise:14:in `builder'
./cruise:68:in `send'
./cruise:68
/usr/lib/ruby/1.8/fileutils.rb:121:in `chdir'
/usr/lib/ruby/1.8/fileutils.rb:121:in `cd'
./cruise:67
[error] svn: OPTIONS of 'https://roadrunner.googlecode.com/svn/trunk': authorization failed (https://roadrunner.googlecode.com)
我尝试跟踪到负责读写配置文件的CC的那块代码,
发现CC加载一个项目的配置文件是在这个方法里面完成的:
def write_config_example(project)
config_example = File.join(RAILS_ROOT, 'config', 'cruise_config.rb.example')
config_in_subversion = File.join(project.path, 'work', 'cruise_config.rb')
cruise_config = File.join(project.path, 'cruise_config.rb')
if File.exists?(config_example) and not File.exists?(config_in_subversion)
FileUtils.cp(config_example, cruise_config)
end
end
我怀疑config_in_subversion 这个文件中的用户名和密码没有起作用。
全文搜索username和password,在./lib/subversioni.rb文件中找到两处代码:
def checkout(revision = nil, stdout = $stdout)
@url or raise 'URL not specified'
options = [@url, path]
# =>zheng.cuizh:add a patch start
# options << "--username" << @username if @username
# options << "--password" << @password if @password
# =>zheng.cuizh:add end
options << "--revision" << revision_number(revision) if revision
# need to read from command output, because otherwise tests break
svn('co', options) do |io|
begin
while line = io.gets
stdout.puts line
end
rescue EOFError
end
end
end
def svn(operation, arguments, options = {}, &block)
command = ["svn"]
command << "--non-interactive" unless @interactive
command << operation
command += arguments.compact
# => zheng.cuizh:add a patch start:
command += ['--username', @username, '--password', @password] if @username and @password
# => zheng.cuizh:add end.
command
execute_in_local_copy(command, options, &block)
end
这个RB文件中,好好读一下可以发现svn是执行svn命令的方法,我之前报错就说svn在checkout的时候没有权限,很可能是执行svn("checkout",options...)这个类似的代码时,没有把用户名和密码传过去。
在网上搜索了一下这段代码,居然找到了一个哥们和我遇到同样的问题,他的文章如下:
[url]http://www.practicalguile.com/2008/02/02/using-cruisecontrolrb-with-repositories-without-anonymous-access/
[/url]
他的解决方案如下:
options = [@url, target_directory]
- options << "--username" << @username if @username
- options << "--password" << @password if @password
options << "--revision" << revision_number(revision) if revision
command << "--non-interactive" unless @interactive
command << operation
command += options.compact.flatten
+ command += ['--username', @username, '--password', @password] if @username and @password
command
搞定!