在 SonarQube 项目上设置自定义属性

Setting custom properties on SonarQube projects

我在 Sonarqube 网站 api 上关注 documentation 以获得 getting/setting 属性。我想在项目 pi_core 上使用 属性 名称 "appName" 和值 "UCFE" 设置一个 属性。最终我想通过 PowerShell 完全自动化,但现在我只是想像文档一样使用 curl 来验证这些概念。我的命令是:

curl -u myID:myPassword -X POST http://myServer.ad1.prod:9000/api/properties?id=appName&value=UCFE&resource=pi_core

我已通过执行其他需要管理员授权的通用 Web api 调用来验证我的 ID 和密码是否有效。当我尝试 运行 以上时,我得到:

{"err_code":200,"err_msg":"property created"}'value' is not recognized as an internal or external command, operable program or batch file.
'resource' is not recognized as an internal or external command, operable program or batch file.

为什么这个命令在我看来与文档完全相同,除了值之外,为什么会出现上述错误?

首先,将 URI 括在引号中;

curl -u myID:myPassword -X POST 'http://myServer.ad1.prod:9000/api/properties?id=appName&value=UCFE&resource=pi_core'
  • & 一开始会在后台发送 3 个命令,如果你不把它括起来的话 运行 来自 shell

  • API 文档经常不完整,测试有限,被放在一起,甚至在博客上显示时无意中陷入转义过程。

在命令行中使用 curl 时,请记住 shell 首先解释命令。

因此,上面的 arg7arg8 作为参数发送给 cURL。 cURL 不知道 "value=UCFE" 是什么意思,因此出现错误:

'value' is not recognized as an internal or external command

当您将要作为 one 参数发送的文本块 引号(例如,URL cURL), 它看起来像这样:


旁注 - 为了完成;

通常引号是单引号还是双引号并不重要,但它们 不同。

  • 单引号大小写:一些APIs,里面有$符号。例如 MYOB 有很多参数如下;这种情况下,如果有很多,用单引号可能会更方便:

    '?$filter=DateOccurred%20ge%20datetime%272016-07-25%2'
    。这种情况下,如果有很多的话,用单引号可能会更方便。

  • 双引号大小写:变量很多:

    "?id=$id&refresh=true&paramlist=$params&authredirect=$authlevel"