{"id":1296,"date":"2021-05-13T19:00:00","date_gmt":"2021-05-13T10:00:00","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1296"},"modified":"2021-05-13T14:10:03","modified_gmt":"2021-05-13T05:10:03","slug":"sonarqube-qualitygate-api","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1296","title":{"rendered":"SonarQube\u3067\u7ba1\u7406\u3057\u3066\u3044\u308bproject\u306eQualityGate\u306e\u72b6\u614b\u3092API\u3067\u53d6\u5f97\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<p>SonarQube\u306eQualityGate\u306e\u72b6\u614b\u3092API\u3092\u4f7f\u3063\u3066\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">API\u78ba\u8a8d<\/h2>\n\n\n\n<p>\u69cb\u7bc9\u3057\u305fSonarQube\u4e0a\u3067\u5229\u7528\u3067\u304d\u308bAPI\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>http:\/\/localhost:9000\/web_api<\/p>\n\n\n\n<p>\u4eca\u56de\u306fQualityGate\u306e\u72b6\u614b\u3092\u78ba\u8a8d\u3057\u305f\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306eAPI\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"976\" height=\"282\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2021\/05\/image-22.png\" alt=\"\" class=\"wp-image-1297\"\/><\/figure>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">curl\u3067\u306e\u5b9f\u884c<\/h2>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/sonarqube-react-single\/\">SonarQube\u3068project\u306e\u9023\u643a\u65b9\u6cd5(React + TypeScript)<\/a>\u3067\u4f5c\u6210\u3057\u305fproject\u306b\u5bfe\u3057\u3066API\u3092\u6295\u3052\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncurl --verbose --noproxy localhost -u admin:password -X GET 'http:\/\/localhost:9000\/api\/qualitygates\/project_status?projectKey=com.example.yourproject:react-template'\n<\/pre><\/div>\n\n\n<p><br>Response\u306f\u4e0b\u306e\u3088\u3046\u306b\u8fd4\u5374\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\n<\/pre><\/div>\n\n\n<p>status\u304c\u300cOK\u300d\u3068\u306a\u3063\u3066\u3044\u308c\u3070QualityGate\u304csuccess\u3057\u3066\u3044\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<br>QualityGate\u304cfailed\u306e\u5834\u5408\u306f\u300cERROR\u300d\u3068\u8fd4\u5374\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p><span class=\"has-inline-color has-vivid-red-color\">point:  SonarQube\u306e\u6700\u65b0\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u306fbasic\u8a8d\u8a3c\u304c\u5fc5\u8981\u3067\u3059\u3002<\/span><\/p>\n\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">QualityGate\u306e\u72b6\u614b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308bshell\u3092\u4f5c\u308b<\/h2>\n\n\n\n<p>API\u3092\u5229\u7528\u3067\u304d\u305f\u306e\u3067\u3001sh\u306b\u307e\u3068\u3081\u307e\u3059\u3002<br>\u3053\u306eshell\u3092CICD\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u5229\u7528\u3059\u308c\u3070\u9759\u7684\u89e3\u6790\u3092CICD\u306b\u7d44\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u203bQualityGate\u306e\u30c1\u30a7\u30c3\u30af\u3092\u884c\u3046\u3088\u3046\u306a\u30d7\u30e9\u30b0\u30a4\u30f3\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n#!\/bin\/sh\n\ncd `dirname $0`\n\nSONAR_PROJECT_KEY=&quot;com.example.yourproject:react-template&quot;\nUSER=&quot;admin&quot;\nPASSWORD=&quot;password&quot;\n\nresponse=`curl --noproxy localhost -u ${USER}:${PASSWORD} -X GET http:\/\/localhost:9000\/api\/qualitygates\/project_status?projectKey=${SONAR_PROJECT_KEY} 2&gt; \/dev\/null`\n\n# return ERROR or OK\nresult_status=`echo $response | tr ',' '\\n' | grep -e &quot;status&quot; | sed 's\/^.*:\/\/' | tr -d '&quot;'`\n\nresult_list=(${result_status\/\/ \/})\nfor result in &quot;${result_list&#x5B;@]}&quot;\ndo\n    if &#x5B; &quot;${result}&quot; = &quot;ERROR&quot; ]\n    then\n        echo &quot;QualityGate is failed&quot;\n        exit &quot;1&quot;\n    fi\ndone\n\necho &quot;QualityGate is Success&quot;\nexit &quot;0&quot;\n\n<\/pre><\/div>\n\n\n<h2 id=\"outline__4\" class=\"wp-block-heading\">\u95a2\u9023<\/h2>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/docker-sonarqube\/\">Docker\u3067SonarQube\u74b0\u5883\u3092\u624b\u65e9\u304f\u69cb\u7bc9\u3059\u308b<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/sonarqube-gradle\/\">SonarQube\u3068project\u306e\u9023\u643a\u65b9\u6cd5(Spring Boot,gradle)<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/ito-u-oti.com\/sonarqube-react-single\/\">SonarQube\u3068project\u306e\u9023\u643a\u65b9\u6cd5(React + TypeScript)<\/a><\/p>\n\n\n\n<h2 id=\"outline__5\" class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/22244163\/how-do-i-pass-credentials-to-sonar-api-calls\">How do I pass credentials to Sonar API calls?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SonarQube\u306eQualityGate\u306e\u72b6\u614b\u3092API\u3092\u4f7f\u3063\u3066\u53d6\u5f97\u3057\u307e\u3059\u3002 API\u78ba\u8a8d \u69cb\u7bc9\u3057\u305fS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1263,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[286,1],"tags":[288,287],"class_list":["post-1296","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sonarqube","category-1","tag-qualitygate","tag-sonarqube"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1296"}],"version-history":[{"count":1,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1296\/revisions"}],"predecessor-version":[{"id":1298,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1296\/revisions\/1298"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/1263"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}