开发者

Adding files to redmine via command line

We have an automatic build system that spits out packages, regression-tested & wrapped into a neat installer, ready for end-users to d/l & deploy. We do tracking of end user support requests/bug reports via redmine. So far we uploaded the packages manually to the resp. 'Files' section of the redmine project, via the web interface.

What I'd like to do is to automate this step. I imagine this would requires a few lines of Ruby to interface with redmine's db. I have zero knowledge about redmine's internals. :)

Basically I want the equivalent of a

mv package-x.y.z.tbz /usr/local/redmine/files/

as a Ruby (or whatever language suits the need) script that creates the right filename and registers the file in redmine's db so it shows up as if it had been uploaded through the Web in开发者_运维问答terface, manually.

Cheers!


I've been frustrated with Redmine about things like this before. But before I go much further: is there a specific reason why you're using the Files section for this? It seems another tool (such as SSH/SFTP for uploading to someplace accessible to HTTP) might be a better fit for your needs. It would also be easily scriptable. Just point people to some constant URL like http://yourcompany.com/productname-current.zip.

If you really need to use Redmine for managing this, you might check out Mechanize: http://mechanize.rubyforge.org/. They should have a RESTful API also, but I've never used it.


I found this post, hope it can help you

Automating packaging and RedMine


I'm a bit late, but I've wrote a Redmine upload tool in Perl, using the WWW::Mechanize module. Please find it on http://github.com/subogero/redgit


As already stated, you can use Mechanize for that.

There's a Python script written by Gert van Dijk's: https://github.com/gertvdijk/redmine-file-uploader

To use it you'll have to install Python Mechanize package first:

easy_install mechanize

If you prefer Ruby, you can use:

require 'mechanize'

# Replaces \ with / and removes "
ARGV.map!{|a|a.gsub('\\','/').gsub(/^"(.+)"$/,'\\1')}

filename    = ARGV[0] || abort('Filename must be specified')
puts "File:              #{filename}"
url         = ARGV[1] || abort('Redmine URL must be specified')
puts "Redmine URL:       #{url}"
username    = ARGV[2] || abort('Redmine username must be specified')
puts "Username:          #{username}"
password    = ARGV[3] || abort('Redmine password must be specified')
puts "Password:          #{'*' * password.length}"
project     = ARGV[4] || abort('Redmine project must be specified')
puts "Project:           #{project}"

login_page_path = '/login'
files_page_path = '/projects/' + project + '/files'

agent = Mechanize.new

# No certificate verification (I had to use this hack because our server is bound to custom port)
# agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE

agent.get(URI.join(url, login_page_path)) do |login_page|
  login_page.form_with(:action => login_page_path) do |login_form|
    login_form.username = username
    login_form.password = password
  end.submit
end

agent.get(URI.join(url, files_page_path + '/new')) do |upload_page|
  upload_page.form_with(:action => files_page_path) do |upload_form|
    upload_form.file_uploads.first.file_name = filename
  end.submit
end

And don't forget to install gem first:

gem install mechanize
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜