{"id":617,"date":"2024-04-16T12:20:47","date_gmt":"2024-04-16T04:20:47","guid":{"rendered":"http:\/\/120.55.184.7\/?p=617"},"modified":"2025-05-10T09:09:12","modified_gmt":"2025-05-10T01:09:12","slug":"jenkins-%e6%9e%84%e5%bb%ba%e9%ab%98%e6%95%88ci-cd%e7%ae%a1%e9%81%93","status":"publish","type":"post","link":"https:\/\/beijian99.top\/?p=617","title":{"rendered":"Jenkins \u6784\u5efa\u9ad8\u6548CI\/CD\u7ba1\u9053"},"content":{"rendered":"\n<p>Jenkins\u4f5c\u4e3a\u5f53\u4eca\u6700\u6d41\u884c\u7684\u5f00\u6e90\u81ea\u52a8\u5316\u670d\u52a1\u5668\uff0c\u5df2\u6210\u4e3a\u73b0\u4ee3DevOps\u5b9e\u8df5\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001Jenkins\u6982\u8ff0<\/h2>\n\n\n\n<p>Jenkins\u662f\u4e00\u4e2a\u57fa\u4e8eJava\u5f00\u53d1\u7684\u5f00\u6e90\u81ea\u52a8\u5316\u670d\u52a1\u5668\uff0c\u4e3b\u8981\u7528\u4e8e\u5b9e\u73b0\u6301\u7eed\u96c6\u6210(CI)\u548c\u6301\u7eed\u4ea4\u4ed8\/\u90e8\u7f72(CD)\u6d41\u7a0b\u3002\u5b83\u7531Kohsuke Kawaguchi\u4e8e2004\u5e74\u521b\u5efa\uff08\u6700\u521d\u540d\u4e3aHudson\uff09\uff0c\u73b0\u5df2\u6210\u4e3a\u4e1a\u754c\u6700\u6d41\u884c\u7684CI\/CD\u5de5\u5177\u4e4b\u4e00\uff0c\u636e\u5f00\u53d1\u8005\u751f\u6001\u7cfb\u7edf\u62a5\u544a\u663e\u793a\uff0c54%\u7684\u5f00\u53d1\u8005\u4f7f\u7528Jenkins\u8fdb\u884cCI\/CD\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6838\u5fc3\u4ef7\u503c<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6301\u7eed\u96c6\u6210<\/strong>\uff1a\u9891\u7e41\u5730\u5c06\u4ee3\u7801\u96c6\u6210\u5230\u5171\u4eab\u4ee3\u7801\u5e93\uff0c\u81ea\u52a8\u6784\u5efa\u548c\u6d4b\u8bd5\uff0c\u5c3d\u65e9\u53d1\u73b0\u95ee\u9898<\/li>\n\n\n\n<li><strong>\u6301\u7eed\u4ea4\u4ed8<\/strong>\uff1a\u786e\u4fdd\u4ee3\u7801\u5728\u4efb\u4f55\u65f6\u5019\u90fd\u53ef\u4ee5\u5b89\u5168\u5730\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883<\/li>\n\n\n\n<li><strong>\u81ea\u52a8\u5316<\/strong>\uff1a\u51cf\u5c11\u4eba\u4e3a\u9519\u8bef\uff0c\u7f29\u77ed\u4ea4\u4ed8\u5468\u671f\uff0c\u8ba9\u5f00\u53d1\u8005\u4e13\u6ce8\u4e8e\u4ee3\u7801\u5f00\u53d1<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Jenkins\u6838\u5fc3\u67b6\u6784<\/h2>\n\n\n\n<p>Jenkins\u91c7\u7528\u4e3b\u4ece(Master-Agent)\u67b6\u6784\u8bbe\u8ba1\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"338\" src=\"http:\/\/120.55.184.7\/wp-content\/uploads\/2025\/04\/image-25.png\" alt=\"\" class=\"wp-image-618\" srcset=\"https:\/\/beijian99.top\/wp-content\/uploads\/2025\/04\/image-25.png 474w, https:\/\/beijian99.top\/wp-content\/uploads\/2025\/04\/image-25-300x214.png 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">1. Jenkins Master<\/h3>\n\n\n\n<p>\u4e3b\u8282\u70b9\u8d1f\u8d23\u534f\u8c03\u6240\u6709\u5de5\u4f5c\u6d41\u7a0b\uff0c\u5305\u542b\u4ee5\u4e0b\u5173\u952e\u7ec4\u4ef6\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f5c\u4e1a(Jobs)<\/strong>\uff1a\u6784\u5efa\u4efb\u52a1\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u662f\u81ea\u7531\u98ce\u683c\u9879\u76ee\u6216\u6d41\u6c34\u7ebf<\/li>\n\n\n\n<li><strong>\u63d2\u4ef6\u7cfb\u7edf<\/strong>\uff1a\u901a\u8fc7\u63d2\u4ef6\u6269\u5c55\u529f\u80fd\uff0c\u73b0\u6709\u8d85\u8fc71800\u4e2a\u63d2\u4ef6<\/li>\n\n\n\n<li><strong>\u5b89\u5168\u63a7\u5236<\/strong>\uff1a\u652f\u6301\u591a\u79cd\u8ba4\u8bc1\u65b9\u5f0f\uff08\u5185\u7f6e\u6570\u636e\u5e93\u3001LDAP\u3001SAML SSO\uff09<\/li>\n\n\n\n<li><strong>\u5168\u5c40\u914d\u7f6e<\/strong>\uff1a\u96c6\u4e2d\u7ba1\u7406\u73af\u5883\u53d8\u91cf\u548c\u5de5\u5177\u914d\u7f6e<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. Jenkins Agent<\/h3>\n\n\n\n<p>\u4ee3\u7406\u8282\u70b9\u662f\u5b9e\u9645\u6267\u884c\u6784\u5efa\u4efb\u52a1\u7684\u5de5\u4f5c\u673a\uff0c\u652f\u6301\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9759\u6001\u4ee3\u7406<\/strong>\uff1a\u5e38\u9a7b\u7684\u7269\u7406\u673a\u6216\u865a\u62df\u673a<\/li>\n\n\n\n<li><strong>\u52a8\u6001\u4ee3\u7406<\/strong>\uff1a\u57fa\u4e8eDocker\/Kubernetes\u7684\u4e34\u65f6\u5bb9\u5668<\/li>\n\n\n\n<li><strong>\u6807\u7b7e\u7cfb\u7edf<\/strong>\uff1a\u901a\u8fc7\u6807\u7b7e\u9650\u5236\u4f5c\u4e1a\u5728\u7279\u5b9a\u4ee3\u7406\u4e0a\u8fd0\u884c<\/li>\n<\/ul>\n\n\n\n<p>\u8fde\u63a5\u65b9\u5f0f\u652f\u6301SSH\u548cJNLP(Java\u7f51\u7edc\u542f\u52a8\u534f\u8bae)\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u6838\u5fc3\u529f\u80fd\u8be6\u89e3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Jenkins Pipeline<\/h3>\n\n\n\n<p>\u6d41\u6c34\u7ebf\u662fJenkins\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u4f7f\u7528<code>Jenkinsfile<\/code>\u5b9a\u4e49CI\/CD\u5de5\u4f5c\u6d41\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npipeline {\n    agent any\n    stages {\n        stage(&#039;Build&#039;) {\n            steps {\n                sh &#039;mvn clean package&#039;\n            }\n        }\n        stage(&#039;Test&#039;) {\n            steps {\n                sh &#039;mvn test&#039;\n            }\n        }\n        stage(&#039;Deploy&#039;) {\n            steps {\n                sh &#039;kubectl apply -f k8s\/&#039;\n            }\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u6d41\u6c34\u7ebf\u652f\u6301\u4e24\u79cd\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u58f0\u660e\u5f0fPipeline<\/strong>\uff1a\u7ed3\u6784\u5316\u66f4\u5f3a\uff0c\u9002\u5408\u521d\u5b66\u8005<\/li>\n\n\n\n<li><strong>\u811a\u672c\u5f0fPipeline<\/strong>\uff1a\u57fa\u4e8eGroovy\uff0c\u7075\u6d3b\u6027\u66f4\u9ad8<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6784\u5efa\u89e6\u53d1\u5668<\/h3>\n\n\n\n<p>Jenkins\u652f\u6301\u591a\u79cd\u89e6\u53d1\u6784\u5efa\u7684\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SCM\u8f6e\u8be2<\/strong>\uff1a\u5b9a\u671f\u68c0\u67e5\u4ee3\u7801\u4ed3\u5e93\u53d8\u66f4<\/li>\n\n\n\n<li><strong>Webhook<\/strong>\uff1a\u4ee3\u7801\u63d0\u4ea4\u65f6\u81ea\u52a8\u89e6\u53d1<\/li>\n\n\n\n<li><strong>\u5b9a\u65f6\u6784\u5efa<\/strong>\uff1a\u4f7f\u7528Cron\u8868\u8fbe\u5f0f\u8c03\u5ea6<\/li>\n\n\n\n<li><strong>\u624b\u52a8\u89e6\u53d1<\/strong>\uff1a\u6309\u9700\u6267\u884c<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u63d2\u4ef6\u751f\u6001\u7cfb\u7edf<\/h3>\n\n\n\n<p>Jenkins\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u4e30\u5bcc\u7684\u63d2\u4ef6\u751f\u6001\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7248\u672c\u63a7\u5236<\/strong>\uff1aGit\u3001SVN\u3001Mercurial<\/li>\n\n\n\n<li><strong>\u6784\u5efa\u5de5\u5177<\/strong>\uff1aMaven\u3001Gradle\u3001Ant<\/li>\n\n\n\n<li><strong>\u6d4b\u8bd5\u6846\u67b6<\/strong>\uff1aJUnit\u3001TestNG\u3001Selenium<\/li>\n\n\n\n<li><strong>\u90e8\u7f72\u76ee\u6807<\/strong>\uff1aDocker\u3001Kubernetes\u3001AWS<\/li>\n\n\n\n<li><strong>\u901a\u77e5<\/strong>\uff1aEmail\u3001Slack\u3001Teams<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u5b89\u88c5\u4e0e\u914d\u7f6e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5b89\u88c5\u65b9\u5f0f<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u72ec\u7acb\u8fd0\u884c<\/strong>\uff1a<code>java -jar jenkins.war<\/code><\/li>\n\n\n\n<li><strong>Servlet\u5bb9\u5668<\/strong>\uff1a\u90e8\u7f72\u5230Tomcat\u7b49\u5bb9\u5668<\/li>\n\n\n\n<li><strong>\u7cfb\u7edf\u5305<\/strong>\uff1a\u5404Linux\u53d1\u884c\u7248\u7684\u5b98\u65b9\u4ed3\u5e93<\/li>\n\n\n\n<li><strong>Docker<\/strong>\uff1a\u5b98\u65b9\u955c\u50cf<code>jenkins\/jenkins<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u521d\u59cb\u914d\u7f6e<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u8bbf\u95ee<code>http:\/\/localhost:8080<\/code>\u5b8c\u6210\u5411\u5bfc<\/li>\n\n\n\n<li>\u5b89\u88c5\u63a8\u8350\u63d2\u4ef6\u96c6<\/li>\n\n\n\n<li>\u521b\u5efa\u7ba1\u7406\u5458\u8d26\u6237<\/li>\n\n\n\n<li>\u914d\u7f6eJDK\u3001Git\u7b49\u5de5\u5177\u8def\u5f84<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6027\u80fd\u4f18\u5316<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5206\u5e03\u5f0f\u6784\u5efa<\/strong>\uff1a\u5229\u7528\u591aAgent\u5206\u62c5\u8d1f\u8f7d<\/li>\n\n\n\n<li><strong>\u8d44\u6e90\u9650\u5236<\/strong>\uff1a\u8bbe\u7f6e\u5e76\u53d1\u6784\u5efa\u6570<\/li>\n\n\n\n<li><strong>\u6e05\u7406\u7b56\u7565<\/strong>\uff1a\u5b9a\u671f\u6e05\u7406\u6784\u5efa\u5386\u53f2\u548c\u5de5\u4ef6<\/li>\n\n\n\n<li><strong>\u76d1\u63a7<\/strong>\uff1a\u96c6\u6210Prometheus+Grafana<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5b89\u5168\u7ba1\u7406<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8ba4\u8bc1<\/strong>\uff1a\u542f\u7528LDAP\u6216SSO\u96c6\u6210<\/li>\n\n\n\n<li><strong>\u6388\u6743<\/strong>\uff1a\u57fa\u4e8e\u89d2\u8272\u7684\u6743\u9650\u63a7\u5236(RBAC)<\/li>\n\n\n\n<li><strong>\u51ed\u8bc1\u7ba1\u7406<\/strong>\uff1a\u4f7f\u7528Jenkins\u52a0\u5bc6\u6216\u5916\u90e8Vault<\/li>\n\n\n\n<li><strong>\u7f51\u7edc\u9694\u79bb<\/strong>\uff1a\u9650\u5236\u8bbf\u95eeIP\u8303\u56f4<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u6d41\u6c34\u7ebf\u8bbe\u8ba1<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6a21\u5757\u5316<\/strong>\uff1a\u5c06\u590d\u6742\u6d41\u7a0b\u5206\u89e3\u4e3a\u591a\u4e2a\u9636\u6bb5<\/li>\n\n\n\n<li><strong>\u5e76\u884c\u6267\u884c<\/strong>\uff1a\u52a0\u901f\u6d4b\u8bd5\u548c\u90e8\u7f72<\/li>\n\n\n\n<li><strong>\u9519\u8bef\u5904\u7406<\/strong>\uff1a\u4f7f\u7528<code>post<\/code>\u5757\u5b9a\u4e49\u6784\u5efa\u540e\u64cd\u4f5c<\/li>\n\n\n\n<li><strong>\u84dd\u7eff\u90e8\u7f72<\/strong>\uff1a\u5b9e\u73b0\u96f6\u505c\u673a\u53d1\u5e03<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u5e94\u7528\u573a\u666f<\/h2>\n\n\n\n<p>Jenkins\u5e7f\u6cdb\u5e94\u7528\u4e8e\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u81ea\u52a8\u5316\u6784\u5efa\u6d4b\u8bd5<\/strong>\uff1aJava\u3001Python\u3001Go\u7b49\u9879\u76ee\u7684CI<\/li>\n\n\n\n<li><strong>\u591a\u4e91\u90e8\u7f72<\/strong>\uff1aAWS\u3001Azure\u3001GCP\u7684CD\u6d41\u7a0b<\/li>\n\n\n\n<li><strong>\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801<\/strong>\uff1aTerraform\u3001Ansible\u7684\u81ea\u52a8\u5316<\/li>\n\n\n\n<li><strong>\u6279\u5904\u7406\u4f5c\u4e1a<\/strong>\uff1a\u6570\u636e\u5907\u4efd\u3001\u62a5\u8868\u751f\u6210<\/li>\n\n\n\n<li><strong>\u79fb\u52a8\u5e94\u7528<\/strong>\uff1aAndroid\/iOS\u7684\u6301\u7eed\u4ea4\u4ed8<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Jenkins\u4f5c\u4e3a\u5f53\u4eca\u6700\u6d41\u884c\u7684\u5f00\u6e90\u81ea\u52a8\u5316\u670d\u52a1\u5668\uff0c\u5df2\u6210\u4e3a\u73b0\u4ee3DevOps\u5b9e\u8df5\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002 \u4e00\u3001Jenkin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[127],"tags":[159],"class_list":["post-617","post","type-post","status-publish","format-standard","hentry","category-ci-cd","tag-jenkins"],"_links":{"self":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts\/617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=617"}],"version-history":[{"count":1,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts\/617\/revisions"}],"predecessor-version":[{"id":619,"href":"https:\/\/beijian99.top\/index.php?rest_route=\/wp\/v2\/posts\/617\/revisions\/619"}],"wp:attachment":[{"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beijian99.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}