{"id":151926,"date":"2020-08-31T16:34:37","date_gmt":"2020-08-31T08:34:37","guid":{"rendered":"http:\/\/4563.org\/?p=151926"},"modified":"2020-08-31T16:34:37","modified_gmt":"2020-08-31T08:34:37","slug":"%e8%af%b7%e6%95%99-%e9%85%8d%e7%bd%ae-jenkins-%e4%bd%bf%e7%94%a8%e7%9a%84%e6%98%af-pipeline-script-from-scm%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e8%bf%99%e4%b8%aa%e4%bb%93%e5%ba%93%e9%87%8c%e9%9d%a2","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=151926","title":{"rendered":"[\u8bf7\u6559] \u914d\u7f6e Jenkins \u4f7f\u7528\u7684\u662f pipeline script from scm,\u5982\u4f55\u83b7\u53d6\u8fd9\u4e2a\u4ed3\u5e93\u91cc\u9762\u7684 shell \u811a\u672c\u5730\u5740"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  [\u8bf7\u6559] \u914d\u7f6e Jenkins \u4f7f\u7528\u7684\u662f pipeline script from scm,\u5982\u4f55\u83b7\u53d6\u8fd9\u4e2a\u4ed3\u5e93\u91cc\u9762\u7684 shell \u811a\u672c\u5730\u5740               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lesteryou <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u524d\u63d0<\/h2>\n<ol>\n<li>\u516c\u53f8\u6709\u5f88\u591a\u9879\u76ee\uff0c\u6700\u8fd1\u90fd\u6253\u7b97\u914d\u7f6e Jenkins \u81ea\u52a8\u5316\uff0c\u4f46\u662f\u5f88\u591a\u4eba\u5bf9\u8fd9\u4e0d\u719f\u6089\uff0c\u6211\u5c31\u8ba1\u5212 \u628a\u8fd9\u4e9b Jenkinsfile \u7edf\u4e00\u7ba1\u7406\uff0c\u65b0\u5efa\u4e00\u4e2a git \u4ed3\u5e93\uff0c\u4e0d\u540c\u7684\u9879\u76ee\u4e0d\u540c\u7684\u8def\u5f84\u53bb\u521b\u5efa Jenkinsfile\uff0c\u516c\u5171\u90e8\u5206\u63d0\u53d6\u51fa\u6765\uff0c\u65b9\u4fbf\u7ef4\u62a4\u3002<\/li>\n<li>Jenkins \u91cc\u9762\u7684 job \u914d\u7f6e\u662f pipeline script from scm\uff0c\u7136\u540e\u9009\u62e9\u5bf9\u5e94\u7684\u811a\u672c\u8def\u5f84\u3002<\/li>\n<li>\u5b9e\u9645\u8fd0\u884c\u4e5f\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0cconsole \u90a3\u8fb9\uff0c\u662f\u5148\u62c9\u53d6 Jenkinsfile \u4ed3\u5e93\u5230\u4e00\u4e2a\u4ee5 [email&#160;protected] \u547d\u540d\u7684\u8def\u5f84\uff0c\u6211\u9700\u8981\u6267\u884c\u7684 shell \u547d\u4ee4\uff0c\u4ee5\u53ca\u4e00\u4e9b\u9700\u8981\u5f15\u5165\u6a21\u5757\u7684 groovy \u6587\u4ef6\u4e5f\u5728\u91cc\u9762\u3002<\/li>\n<li>\u5728\u5f53\u524d\u9879\u76ee\u5bf9\u5e94\u7684 Jenkinsfile \u91cc\u9762\u901a\u8fc7 load\uff0c\u5f15\u5165\u516c\u5171\u6a21\u5757\u7684 groovy \u662f\u6ca1\u95ee\u9898\u7684\u3002<\/li>\n<\/ol>\n<pre><code> - lib  \/\/\u7c7b\u5e93  - pipeline      - module \/\/\u6a21\u5757       qywechat-notice    ...  - shell \/\/ shell \u811a\u672c      notice.sh  - src   \/\/ \u5404\u9879\u76ee\u7684 Jenkinsfile \u6587\u4ef6  <\/code><\/pre>\n<h2>\u95ee\u9898<\/h2>\n<ol>\n<li>\u4f46\u662f \u6211\u9700\u8981\u6267\u884c\u5176\u4e2d\u7684 shell \u547d\u4ee4\u7684\u65f6\u5019\uff0c\u65e0\u6cd5\u6267\u884c\u4e86\uff0c\u6211\u8fdb\u5230 Jenkins \u670d\u52a1\u5668\uff0c\u53d1\u73b0 shell \u6587\u4ef6\u7684\u5730\u5740\u662f\u5728 [email&#160;protected] \u4e0b\u9762\uff0c\u800c jenkins \u7684\u73af\u5883\u53d8\u91cf env.WORKSPACE \u662f project_name,\u800c\u8fd9\u8def\u5f84\u4e5f\u4e0d\u80fd\u786c\u7f16\u7801\uff0c\u5199\u6b7b\uff0c\u6240\u4ee5\u6709\u6ca1\u6709\u4ec0\u4e48\u65b9\u5f0f\u53ef\u4ee5\u83b7\u53d6\u5230 shell \u6587\u4ef6\u7684\u771f\u5b9e\u8def\u5f84\u3002<\/li>\n<\/ol><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3176990\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : monsterxx03 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6362\u4e2a\u601d\u8def, \u5171\u4eab\u5e93\u91cc\u5e94\u8be5 export \u4e00\u4e2a runScript \u51fd\u6570, \u5916\u90e8\u4e0d\u8981\u5173\u5fc3 script \u5177\u4f53\u8def\u5f84.<\/p>\n<p>jenkins pipeline \u6709\u70b9\u5751\u7684, \u5982\u679c\u4f60\u7684 shell script \u8981\u6c42\u5fc5\u987b\u5728\u811a\u672c\u540c\u4e00\u7ea7\u76ee\u5f55\u8fd0\u884c, \u5c1d\u8bd5\u7528 dir() \u5207\u5230 workspace \u4e4b\u5916\u7684\u8def\u5f84\u884c\u4e0d\u901a\u7684, \u4f1a\u62a5\u6743\u9650\u9519\u8bef                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3176991\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : lesteryou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @monsterxx03 \u4f60\u597d\uff0c\u8bf7\u95ee\u8fd9\u4e2a `export \u4e00\u4e2a runScript \u51fd\u6570`\uff0c\u4e0d\u592a\u7406\u89e3\uff0c\u662f\u5b9a\u4e49\u4e2a\u51fd\u6570\u8fd4\u56de shell \u5185\u5bb9\uff1f\u60a8\u53ef\u4ee5\u8be6\u7ec6\u8bf4\u4e0b\u5417\uff0c\u8c22\u8c22\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3176992\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : monsterxx03 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lesteryou \u6211\u6709\u70b9\u60f3\u591a\u4e86, \u4f60\u7684\u9700\u6c42\u7528 resources folder \u5c31\u53ef\u4ee5\u4e86 https:\/\/www.jenkins.io\/doc\/book\/pipeline\/shared-libraries\/#loading-resources                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>[\u8bf7\u6559] \u914d\u7f6e Jenkins \u4f7f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/151926"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=151926"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/151926\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=151926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=151926"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=151926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}