{"id":482,"date":"2019-10-11T14:56:47","date_gmt":"2019-10-11T06:56:47","guid":{"rendered":"https:\/\/www.yinyubo.cn\/?p=482"},"modified":"2022-05-17T09:42:07","modified_gmt":"2022-05-17T01:42:07","slug":"jenkins","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=482","title":{"rendered":"Jenkins\u6839\u636epipeline\u7684\u8fd0\u884c\u7ed3\u679c\uff0c\u7ed9gitea\u7684\u5408\u5e76\u8bf7\u6c42pull-request\u8fdb\u884c\u8bc4\u8bba"},"content":{"rendered":"<h1>\u9700\u6c42<\/h1>\n<p>Jenkins\u6211\u4eec\u5df2\u7ecf\u96c6\u6210\u4e86sonarqube\uff0c\u5e76\u4e14\u901a\u8fc7sonarqube\u7684gate\u80fd\u83b7\u53d6\u5230\u7ed3\u679c\uff0c\u5e76\u4e14\u544a\u77e5Jenkins\u662f\u6210\u529f\u8fd8\u662f\u5931\u8d25\u3002\u4f46\u662f\u8fd9\u6837\u8fd8\u4e0d\u591f\uff0c\u6211\u4eec\u9700\u8981\u9650\u5236\u961f\u53cb\u5411\u4e3b\u5206\u652f\u63d0\u4ea4\u4ee3\u7801\u3002\u6211\u4eec\u9501\u4f4f\u4e86master\u5206\u652f\uff0c\u961f\u53cb\u53ea\u80fd\u901a\u8fc7\u5728gitea\u4e2d\u5411master\u5206\u652f\u63d0\u4ea4pull-request\u5e76\u4e14\u901a\u8fc7\u4e86sonarqube\u7684\u4ee3\u7801\u8d28\u91cf\u68c0\u67e5\uff0c\u6211\u4eec\u624d\u5141\u8bb8\u5408\u5e76\u8fdb\u4e3b\u5206\u652f\u3002\u6211\u4eec\u6025\u9700\u8981\u4e00\u4e2a\u8bc4\u8bba\u529f\u80fd\uff0c\u544a\u77e5\u6211\u4eec\uff0c\u8fd9\u6b21\u7684\u5408\u5e76\u8bf7\u6c42\u662f\u5426\u5141\u8bb8\u5408\u5e76<\/p>\n<h1>\u6700\u7ec8\u6548\u679c\u56fe<\/h1>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-483 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-1-1024x534.png\" alt=\"\" width=\"900\" height=\"469\" \/><\/p>\n<h1>\u5173\u952e\u70b9<\/h1>\n<p>1.\u5728gitea\u4e2d\u521b\u5efa\u4e00\u4e2a\u7528\u6237\uff0c\u7528\u8fd9\u4e2a\u7528\u6237\u4e13\u95e8\u8fdb\u884c\u8bc4\u8bba\uff0c\u4f8b\u5982\u6211\u8fd9\u91cc\u7684\u201cguardian\u201d\u8d26\u6237<br \/>\n2.\u628a\u8be5\u8d26\u6237\u52a0\u5165Jenkins\u7684\u51ed\u636e\u7ba1\u7406\u91cc\u3002\u5982\u4e0b\u56fe\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-484 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-2-2-1024x304.png\" alt=\"\" width=\"900\" height=\"267\" \/><br \/>\n3.\u5728gitea\u7684\u5b98\u65b9\u6587\u6863\u91cc\u627e\u5230\u6dfb\u52a0\u8bc4\u8bba\u7684API\uff0c\u94fe\u63a5\u5982\u4e0b\uff1ahttps:\/\/try.gitea.io\/api\/swagger#\/issue\/issueCreateComment<br \/>\n4.\u5728Jenkins\u7684pipeline\u4e2d\u5b9a\u4e49\u6dfb\u52a0\u8bc4\u8bba\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u5206\u522b\u653e\u5728success\u548cunsuccessful\u7ed3\u679c\u91cc\u3002\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:python decode:true EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">\/\/\u8fd9\u4e00\u6bb5\u662f\u6dfb\u52a0\u8bc4\u8bba\u7684\u65b9\u6cd5\ndef gitComment(String comment) {\n        script {\n                if (IS_PULL_REQUEST==true){\n                     numb=env.BRANCH_NAME.split('-')[-1];\n                    def check_result = '{\"body\": \"'+comment+'\"}';\n                    def response = httpRequest httpMode: 'POST',\n                    url: 'https:\/\/{\u670d\u52a1\u5668\u5730\u5740}\/git\/api\/v1\/repos\/{\u6240\u5c5e\u4eba}\/{\u4ed3\u5e93\u540d}\/issues\/'+numb+'\/comments',\n                    authentication : '74849b03-79ba-43f5-b4b6-920',\n                    acceptType: 'APPLICATION_JSON_UTF8', contentType: 'APPLICATION_JSON_UTF8',\n                    requestBody : check_result\n                }\n        }\n}<\/code><\/pre>\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">\/\/\u6839\u636e\u6267\u884c\u7ed3\u679c\uff0c\u8fdb\u884c\u4e0d\u540c\u7684\u8bc4\u8bba\npost {\n        success {\n            gitComment(\"\u901a\u8fc7CI\u68c0\u67e5\uff0c\u5141\u8bb8\u5408\u5e76\")\n        }\n        unsuccessful {\n            gitComment(\"\u6ca1\u6709\u901a\u8fc7CI\u68c0\u67e5\uff0c\u5efa\u8bae\u4e0d\u8981\u5408\u5e76\"+env.RUN_DISPLAY_URL)\n        }\n    }<\/code><\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\"><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42 Jenkins\u6211\u4eec\u5df2\u7ecf\u96c6\u6210\u4e86sonarqube\uff0c\u5e76\u4e14\u901a\u8fc7sonarqube\u7684gate\u80fd\u83b7\u53d6\u5230\u7ed3\u679c\uff0c\u5e76\u4e14\u544a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-k8s"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=482"}],"version-history":[{"count":1,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/482\/revisions"}],"predecessor-version":[{"id":903,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/482\/revisions\/903"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}