SonarQube 5.6恢复质量配置文件

时间:2017-01-30 13:20:58

标签: curl sonarqube

我正在尝试使用curl通过Web API在SonarQube v.5.6.4的全新安装上恢复质量配置文件。

在c:\ temp中我有一个导出的"声纳方式"运行Sonar的配置文件,我已将其重命名为test.xml(在内部,名称也更改为测试,以便两个配置文件都是"不同的")。

从c:\ temp位置,我使用了以下curl命令:

curl -v -X POST -u admin:admin --header "Content-Type: application/xml"
     "http://localhost:9000/api/qualityprofiles/restore" -d backup=test.xml

回应是:

500 Internal Server Error If you are the administrator of this website, 
then please read this web application's log file to find out what went wrong.

无论我如何更改curl-command(使用不同的内容类型,使用-F参数,使用@ before file name),我都无法解决此问题。

此外,我检查了Sonar日志,如下所示:

2017.01.30 14:13:14 ERROR web[rails] /!\ FAILSAFE /!\  Mon Jan 30 14:13:14 +0100 2017
  Status: 500 Internal Server Error
  undefined method `name' for nil:NilClass
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/xml_mini/rexml.rb:29:in `merge_element!'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/xml_mini/rexml.rb:18:in `parse'
    org/jruby/RubyKernel.java:2227:in `send'
    C:1:in `parse'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/activesupport-2.3.15/lib/active_support/core_ext/hash/conversions.rb:171:in `from_xml'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/params_parser.rb:34:in `parse_formatted_parameters'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/params_parser.rb:11:in `call'
    file:/C:/bin/sonarqube-5.6.4/lib/server/jruby-rack-1.1.13.2.jar!/jruby/rack/session_store.rb:70:in `context'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/rack-1.1.6/lib/rack/session/abstract/id.rb:58:in `call'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/failsafe.rb:26:in `call'
    C:/bin/sonarqube-5.6.4/web/WEB-INF/gems/gems/actionpack-2.3.15/lib/action_controller/dispatcher.rb:106:in `call'
    file:/C:/bin/sonarqube-5.6.4/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:34:in `serve_rails'
    file:/C:/bin/sonarqube-5.6.4/lib/server/jruby-rack-1.1.13.2.jar!/rack/adapter/rails.rb:39:in `call'
    file:/C:/bin/sonarqube-5.6.4/lib/server/jruby-rack-1.1.13.2.jar!/rack/handler/servlet.rb:22:in `call'

版本5.6.4有问题吗?

提前感谢您的任何反馈。

2 个答案:

答案 0 :(得分:2)

The answer to my problem was this command:

curl -v POST -u admin:admin "http://localhost:9000/api/qualityprofiles/restore"  
--form backup=@test.xml

It looks like I didn't try this combination before.

The response was 200 OK:

 HTTP/1.1 100 Continue
 HTTP/1.1 200 OK
 Server: Apache-Coyote/1.1
 Set-Cookie: JSESSIONID=A20898D27A0D843EEC6ED9791CABEB49; Path=/; HttpOnly
 X-Runtime: 265
 ETag: "7cce49c3a8a16a16c8c48cc4942df042"
 Cache-Control: no-cache, no-store, must-revalidate
 X-Frame-Options: SAMEORIGIN
 X-XSS-Protection: 1; mode=block
 X-Content-Type-Options: nosniff
 Content-Type: application/json;charset=utf-8
 Content-Length: 166
 Date: Mon, 30 Jan 2017 14:19:51 GMT

答案 1 :(得分:1)

如果您将所有xml备份文件放在一个目录中,则可以通过以下方式仅使用一个命令恢复所有这些文件:
C:> for / R. %1 IN(* .xml)DO curl.exe -v -X POST -u admin:admin_password " http://your_server:9000/sonar/api/qualityprofiles/restore" - 形成备份= @%1

干杯

的Massimo