index.html 48.9 KB
Newer Older
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1 2 3 4 5
<!DOCTYPE html>
<html class="no-js" lang="zh-CN">
  <head>
    <meta charset="utf-8">
    
6 7 8
    <link rel="preload" href="https://jenkins-zh.github.io/files/muli-latin-200.woff2" as="font" type="font/woff2" crossorigin>
    <link rel="preload" href="https://jenkins-zh.github.io/files/muli-latin-400.woff2" as="font" type="font/woff2" crossorigin>
    <link rel="preload" href="https://jenkins-zh.github.io/files/muli-latin-800.woff2" as="font" type="font/woff2" crossorigin>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
9 10 11

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     
LinuxSuRen's avatar
LinuxSuRen 已提交
12 13
     <title>MPL - 模块化的流水线库 - Jenkins 中文社区</title>
     <meta name="HandheldFriendly" content="True">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
14
    <meta name="MobileOptimized" content="320">
LinuxSuRen's avatar
LinuxSuRen 已提交
15 16 17 18
    
    <meta name="description" content="Jenkins 流水线共享库技术实践">
    
    
LinuxSuRen's avatar
LinuxSuRen 已提交
19
    <meta name="keywords" content="Jenkins,Jenkins中文社区,Jenkins官方公众号,持续集成,持续交付,开源社区,DevOps">
LinuxSuRen's avatar
LinuxSuRen 已提交
20
    
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
21 22

    <meta name="viewport" content="width=device-width,minimum-scale=1">
23
     <meta name="generator" content="Hugo 0.53" />
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
24 25

      
LinuxSuRen's avatar
LinuxSuRen 已提交
26
        <META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
27 28
      

LinuxSuRen's avatar
LinuxSuRen 已提交
29
    <link href='/dist/main.css' rel='stylesheet' type="text/css" /><style>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
30 31 32 33 34 35 36 37
  img.avatar {
    width: 32px;
    display: inline;
  }
</style>
<meta property="og:title" content="MPL - 模块化的流水线库" />
<meta property="og:description" content="Jenkins 流水线共享库技术实践" />
<meta property="og:type" content="article" />
38
<meta property="og:url" content="https://jenkins-zh.github.io/wechat/articles/2019/03/2019-01-08-mpl-modular-pipeline-library/" /><meta property="article:published_time" content="2019-03-06T00:00:00&#43;00:00"/>
39 40
<meta property="article:modified_time" content="2019-03-06T00:00:00&#43;00:00"/>

LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<meta itemprop="name" content="MPL - 模块化的流水线库">
<meta itemprop="description" content="Jenkins 流水线共享库技术实践">


<meta itemprop="datePublished" content="2019-03-06T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2019-03-06T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="496">



<meta itemprop="keywords" content="jenkins,pipeline,shared-library," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="MPL - 模块化的流水线库"/>
<meta name="twitter:description" content="Jenkins 流水线共享库技术实践"/>

LinuxSuRen's avatar
LinuxSuRen 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-4216293-5"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-4216293-5');



var trackOutboundLink = function(id, url) {
  console.log("track:", id, url)
  gtag('event', 'click', {
    'event_category': 'outbound',
    'event_label': id,
    'transport_type': 'beacon',
    'event_callback': function(){document.location = url;}
  });
}

</script>

      
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
80 81 82 83 84 85 86 87
  </head>
  <body class="ma0 sans-serif bg-primary-color-light">
    
<nav class="bg-primary-color-dark pv4 w-100" role="navigation">

  <div class="center flex-ns flex-wrap items-center justify-start mw9">

    <h1 class="dim f3 lh-solid ml0-ns mr0 mr4-l mv0 pl3 pl4-ns">
88
      <a href="https://jenkins-zh.github.io" class="link white">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
89 90 91 92 93 94 95 96 97 98
         Jenkins 中文社区
      </a>
    </h1>
    <ul class="list ma0 pa0 dn dib-l">
      
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/wechat/" class="dim link light-silver"
            >
LinuxSuRen's avatar
LinuxSuRen 已提交
99
            博客
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
100 101 102 103 104
              
            
          </a>
        </li>
      
LinuxSuRen's avatar
LinuxSuRen 已提交
105 106 107 108 109 110 111 112 113 114 115
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/tutorial/" class="dim link light-silver"
            >
            教程
              
            
          </a>
        </li>
      
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
116 117 118 119 120 121 122 123 124 125 126
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/event/" class="dim link light-silver"
            >
            活动
              
            
          </a>
        </li>
      
LinuxSuRen's avatar
LinuxSuRen 已提交
127 128 129 130 131 132 133 134 135 136 137
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/partner/" class="dim link light-silver"
            >
            合作伙伴
              
            
          </a>
        </li>
      
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/about/" class="dim link light-silver"
            >
            关于我们
              
            
          </a>
        </li>
      
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="http://jenkins.io/zh" class="dim link light-silver"
            target="_blank">
            Jenkins 官网
              
            
              <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10" viewBox="0 0 32 32" class="fill-current v-base" aria-label="External Link">
<path d="M25.152 16.576v5.696q0 2.144-1.504 3.648t-3.648 1.504h-14.848q-2.144 0-3.648-1.504t-1.504-3.648v-14.848q0-2.112 1.504-3.616t3.648-1.536h12.576q0.224 0 0.384 0.16t0.16 0.416v1.152q0 0.256-0.16 0.416t-0.384 0.16h-12.576q-1.184 0-2.016 0.832t-0.864 2.016v14.848q0 1.184 0.864 2.016t2.016 0.864h14.848q1.184 0 2.016-0.864t0.832-2.016v-5.696q0-0.256 0.16-0.416t0.416-0.16h1.152q0.256 0 0.416 0.16t0.16 0.416zM32 1.152v9.12q0 0.48-0.352 0.8t-0.8 0.352-0.8-0.352l-3.136-3.136-11.648 11.648q-0.16 0.192-0.416 0.192t-0.384-0.192l-2.048-2.048q-0.192-0.16-0.192-0.384t0.192-0.416l11.648-11.648-3.136-3.136q-0.352-0.352-0.352-0.8t0.352-0.8 0.8-0.352h9.12q0.48 0 0.8 0.352t0.352 0.8z"></path>
</svg>

            
          </a>
        </li>
      
    </ul>

    <div class="db dib-ns pl3"><form id="site-search-form" action="" role="search">
  <fieldset class="bn ma0 pa0">
    <label class="clip" for="email-address">Search</label>
    <input type="search" id="search-input" class="needs-js bg-left bg-transparent bn f5 input-reset lh-solid mt3 mt0-ns pl4 pv2 w5 white"
      placeholder="搜索文档" type="text"
      name="email-address" value="" style="background-image:url('/images/icon-search.png');background-size:16px 16px;">
  </fieldset>
</form>
</div>

    <div class="list ma0 pa0 dn dib-l"></div>

    <span class="absolute mt1 mt2-l pr3 right-0 top-0">

<a class="github-button needs-js link primary-color-dark" href="https://github.com/jenkins-zh/jenkins-zh/" data-size="large" data-show-count="false" aria-label="Star Jenkins WeChat GitHub">Star</a>
</span>

  </div>
</nav>

    
    <main role="main" class="content-with-sidebar min-vh-100 pb7 pb0-ns">
      
<main>
  <article class="w-100 ph4 pb5 pb6-ns pt1 pt5-ns">
    <div class="flex-l">
      

      <div class="order-2 w-100 w-20-l ph5-m ph0-l mb4 sticky">





  <aside class="mw5 br3 mv3 nested-links">
    
    
      
LinuxSuRen's avatar
LinuxSuRen 已提交
205
        <h3 class="f4 dib author">
LinuxSuRen's avatar
LinuxSuRen 已提交
206 207 208 209 210
            翟志军
        </h3>

      
      
LinuxSuRen's avatar
LinuxSuRen 已提交
211
        <p class="lh-copy measure center mt0 f6 black-60 bio">
LinuxSuRen's avatar
LinuxSuRen 已提交
212 213 214
          《Jenkins 2.x实践指南》作者,购买地址:https://item.jd.com/12512889.html?dist=jd

        </p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
215
      
LinuxSuRen's avatar
LinuxSuRen 已提交
216
      <a href="https://github.com/zacker330" target="_blank" class="link dim v-mid dib">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
217 218 219 220 221
        <svg version="1.1" fill="gray" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="18" viewBox="0 0 27 32">
<path d="M9.28 21.44q0.064-0.128-0.064-0.256-0.16-0.128-0.256-0.032-0.064 0.128 0.064 0.224 0.16 0.128 0.256 0.064zM8.768 20.704q-0.096-0.128-0.224-0.096-0.096 0.096 0 0.224 0.128 0.16 0.224 0.096t0-0.224zM8.032 19.968q0.032-0.064-0.096-0.128-0.128-0.032-0.128 0.032-0.064 0.096 0.064 0.16 0.16 0.032 0.16-0.064zM8.416 20.384q0.032 0 0.032-0.064t-0.064-0.096q-0.128-0.128-0.192-0.064t0.032 0.192q0.096 0.096 0.192 0.032zM9.952 21.728q0.032-0.128-0.16-0.192-0.16-0.064-0.224 0.064t0.16 0.192q0.16 0.064 0.224-0.064zM10.688 21.792q0-0.16-0.192-0.16t-0.192 0.16 0.192 0.128 0.192-0.128zM11.392 21.664q-0.032-0.128-0.224-0.096t-0.16 0.16q0.032 0.16 0.192 0.096t0.192-0.16zM22.848 16q0-3.776-2.656-6.464t-6.464-2.688-6.464 2.688-2.688 6.464q0 2.976 1.76 5.376t4.48 3.296q0.32 0.064 0.48-0.096t0.16-0.352q0-0.928-0.032-1.696-0.096 0.032-0.256 0.064t-0.64 0.032-0.864-0.096-0.768-0.352-0.544-0.736q-0.416-1.056-1.024-1.312-0.032-0.032-0.064-0.064l-0.16-0.16t-0.096-0.16 0.064-0.128 0.352-0.064q0.096 0 0.256 0.032t0.544 0.288 0.576 0.64q0.288 0.48 0.672 0.736t0.768 0.256 0.704-0.064 0.512-0.16q0.128-0.864 0.608-1.248-0.896-0.096-1.536-0.32t-1.312-0.704-0.992-1.344-0.352-2.144q0-1.408 0.96-2.464-0.448-1.088 0.096-2.4 0.32-0.128 0.96 0.128t1.088 0.512l0.448 0.288q1.056-0.288 2.304-0.288t2.272 0.288q0.192-0.128 0.512-0.32t0.992-0.448 1.024-0.16q0.512 1.312 0.096 2.4 0.928 1.056 0.928 2.464 0 1.024-0.256 1.792t-0.64 1.248-0.928 0.8-1.12 0.448-1.216 0.224q0.608 0.544 0.608 1.696 0 0.704 0 1.6t-0.032 0.896q0 0.224 0.16 0.352t0.48 0.096q2.752-0.928 4.512-3.296t1.728-5.376zM27.424 7.424v17.152q0 2.112-1.504 3.616t-3.648 1.536h-17.12q-2.144 0-3.648-1.536t-1.504-3.616v-17.152q0-2.112 1.504-3.616t3.648-1.536h17.12q2.144 0 3.648 1.536t1.504 3.616z"></path>
</svg>

      </a>
LinuxSuRen's avatar
LinuxSuRen 已提交
222 223 224 225 226 227 228 229 230

  
  <div>
    作者:<span class="originalAuthor">sparshev</span>
    <div>
      <a class="originalLink" href="https://jenkins.io/blog/2019/01/08/mpl-modular-pipeline-library/" target="_blank">原文链接</a>
    </div>
  </div>
  
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
  </aside>


<aside class="fixed-lTK mw5-l right-0 f6 bl-l b--moon-gray pv4 pv0-ns ph4-l nested-list-reset nested-links nested-copy-line-height">
	

	<div date-pref>
		<a href=".." class="dib f6 pl1 hover-bg-light-gray br-100">
			<svg class="fill-current" height="30px" viewBox="0 0 24 24" width="30px" xmlns="http://www.w3.org/2000/svg">
      <path transform="rotate(90 11.704999923706055,12.000000000000002) " d="m15.41,7.41l-1.41,-1.41l-6,6l6,6l1.41,-1.41l-4.58,-4.59l4.58,-4.59z" id="svg_1"/>
    <path d="M0 0h24v24H0z" fill="none"/>
</svg>

		</a>
		
		
247
			<a href="https://jenkins-zh.github.io/wechat/articles/2019/03/2019-03-13-ready-for-cdf/" class="dib f6 pl1 hover-bg-light-gray br-100" title="为 Continuous Delivery Foundation 的成立感到兴奋 ">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
248 249 250 251 252 253 254 255 256
				<svg class="fill-current" height="30px" viewBox="0 0 24 24" width="30px" xmlns="http://www.w3.org/2000/svg">
    <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
    <path d="M0 0h24v24H0z" fill="none"/>
</svg>

			</a>
		

		
257
			<a href="https://jenkins-zh.github.io/wechat/articles/2019/02/2019-02-27-jenkins-script-console-in-practice/" class="dib f6 pr1 hover-bg-light-gray br-100" title="批量修改 Jenkins 任务的技巧">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270
			<svg class="fill-current" height="30px" viewBox="0 0 24 24" width="30px" xmlns="http://www.w3.org/2000/svg">
    <path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/>
    <path d="M0 0h24v24H0z" fill="none"/>
</svg>

			</a>
		
	</div>

</aside>
</div>

      <div class="order-1 w-80-l mw8 ph0 ph5-ns mid-gray nested-copy-line-height no-underline nested-links nested-img nested-copy-seperator nested-blockquote mt0-ns" style="flex-grow:1;">
LinuxSuRen's avatar
LinuxSuRen 已提交
271
        <button id="copyMe" onclick="copyMe()" style="display: none">Copy Me</button>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
        <div class="documentation-copy center mw8">
          <div id="readout" class="fixed right-0 bottom-0">
          </div>
          <header class="flex-none w-100">
  
  <h1 class="lh-title mb3 mv0 pt3 primary-color-dark">MPL - 模块化的流水线库</h1>
</header>

<aside class="bt bw1 pt3 mt2 mid-gray b--mid-gray fn w-100">
  
    <div class="f4 fw4 lh-copy">
      Jenkins 流水线共享库技术实践
    </div>
  

  
</aside>



<div class="prose" id="prose">



<h3 id="mpl-模块化的流水线库">MPL - 模块化的流水线库</h3>

<p>尽管通过自动化部署加快了开发速度,但由于在 DevOps 方面缺少协作,我们一个客户正因此而放慢产品的上市时间。虽然他们也投入了资源来做 DevOps ,但每条生产流水线都是独立设置的,迫使团队为每个项目重新造轮子。更糟糕的是,由于没有跨团队协作,平台中的任何错误又会出现在每条新的流水线中。许多客户都有类似的问题存在,因此我们决定开发一个既能帮助现有客户,又能适应未来使用需求的通用工具。使用通用框架且标准化的 CI/CD 平台是最显而易见的选择,但这将导致缺少灵活性的单体结构(monolithic structure),最终会变得举步维艰。每个团队都需要在自己的流水线上工作,基于此,我们开发了一个方便 DevOps 流水线的每个可重用部分可供以后使用的解决方案 — Jenkins 驱动的模块化流水线库。</p>

<h3 id="解决方案-模块化流水线库">解决方案:模块化流水线库</h3>

<p>模块化流水线库(译注:modular pipeline library,简称 MPL)是一个高度灵活的 Jenkins 流水线共享库,它可以轻松将最佳实践共享到整个公司。它具有清晰的模块化结构,先进的测试框架,多级嵌套的能力,流水线配置系统,被改进了的错误处理机制以及许多其他有用的组件。</p>

<p>我们将通过以下几部分内容深入了解并解释 MPL 是如何工作的:</p>

<ol>
<li>探索用于构建 MPL 的技术和工具</li>
<li>回顾MPL,并说明它为何有效</li>
<li>一步一步在流水线样例中使用 MPL</li>
<li>深入研究 MPL 的一些重要的组件,例如测试框架和嵌套库</li>
</ol>

<p>首先,让我们介绍构建 MPL 时使用到的关键技术。</p>

<h3 id="使用共享库和-jenkins-流水线构建-mpl">使用共享库和 Jenkins 流水线构建 MPL</h3>

<p>我们的 Jenkins 自动化平台最近收到了一些 Jenkins 流水线的更新。这些更新允许我们创建一个 Jenkinsfile 文件来描述整条流水线,并用于执行一系列不言自明的脚本。这提高了最终用户对 CI/CD 自动化流程的可视化程度,并提高了 DevOps 团队对流水线的可支持性。</p>

<p>然而,流水线存在一个很大的问题:很难用唯一的流水线支持多个 Jenkinsfile 文件(因此存在多少个项目就存在多少个 Jenkinsfile 文件)。我们需要一个地方存放公共逻辑,这正是 Jenkins 共享库能够实现的。共享库用于存放流水线公共的部分,它定义在 Jenkinsfile 文件中,并允许在其中使用接口简化自动化脚本。</p>

<p>虽然共享库允许你存储公共逻辑并操作 Jenkins,但它们并没有提供一种好的方式去使用这些公共逻辑。所以,MPL 通过允许用户创建易于理解的流程描述来优化流水线和共享库,然后方便其他团队使用。</p>

<h3 id="mpl-致力于创建跨团队协作-devops-流程">MPL 致力于创建跨团队协作 DevOps 流程</h3>

<p>通过 MPL,我们现在能够跨团队协作和共享 DevOps 实践,轻松地为特定的项目指定特定的流水线,并能在将它们集成到 MPL 库中之前进行调试和测试。每个团队都可以创建一个嵌套库,在其中增加流水线和模块,并在流水线中使用,这样还可以提高流水线的可视化程度。MPL 能够适用于任何包含 Jenkinsfile 文件的项目,还可以根据项目团队的需要灵活地管理它。</p>

<p>MPL 的核心是提供一种简单的方法:</p>

<ul>
<li>通过引入模块分离流水线和步骤</li>
<li>使用简单的接口描述模块中的步骤</li>
<li>测试所描述的模块并与其他流水线和项目共享结果</li>
</ul>

<p>MPL 中还有许多其他功能,但本质上它是一个解决 DevOps 一般性协作问题的平台。为了简化开发和手动测试,MPL 提供了模块覆盖和继承模型,允许用户在不影响其他任何情况下测试项目中的特定修复。在 Jenkins 中,一个模块就是一个文件,其中包含脚本步骤和逻辑,以实现简单的目标(构建工件,运行测试,创建图像等)。这些模块在流水线的阶段中可以被组合使用,而且任何了解 Jenkins 流水线语法的人都可以轻松读懂。</p>

<p>MPL 允许用户使用库的核心特性(结构,模块,管道)并创建嵌套库以满足特定 DevOps 团队的需求。DevOps 团队可以在他们的项目中使用任何自定义的逻辑来组装一条完整的流水线。他们还可以通过多种方式覆盖和继承核心 MPL 模块,或者轻松地与其他团队分享自定义模块。接下来的信息,展示了这些模块的适用范围:</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
339
<p><img src="fig01-layers-of-the-mpl.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
340 341 342

<p>你还可以在模块中指定某些流水线所需的后续步骤。例如,动态部署模块的执行会创建测试环境,当流水线结束时,它又会销毁该测试环境。想要仔细查看 MPL 调用过程,请查看下图:</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
343
<p><img src="fig02-the-mpl-process.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377

<p>此图显示了 MPL 的执行。首先,你必须创建一个 Jenkins 任务,它将调用 Jenkinsfile(例如,当源代码被更改时),之后 Jenkinsfile 将调用流水线。流水线逻辑可以被定义在这些位置:MPL 端、Jenkins 任务的流水线脚本中 、嵌套库或项目 Jenkinsfile 中。最后,流水线的各个阶段将调用模块,而这些模块所使用的特性,可能来自 groovy 逻辑,流水线步骤或者共享库中的步骤。</p>

<p>现在我们已经完成对解决方案的概述,接下来,让我们通过一个简单的流水线来了解 MPL 是如何工作的。</p>

<h3 id="流水线在-mpl-中执行的示例">流水线在 MPL 中执行的示例</h3>

<p>假设你有一个常规的 Java Maven 项目。你在项目中创建 Jenkinsfile,并希望使用 DevOps 团队准备的默认流水线。MPL 本身就提供一个简单的流水线:核心 MPLPipeline 。这是一个非常简单的流水线,但对于想要尝试 MPL 的人来说,这是一个很好的开端。我们来看一下这个简单的 Jenkinsfile 文件:</p>

<pre><code class="language-groovy">@Library('mpl') _
MPLPipeline {}
</code></pre>

<p>这个 Jenkinsfile 文件只包含两行代码,一行加载 MPL 逻辑,另一行运行流水线。大多数的共享库实现了像这样的接口,调用步骤并提供参数。MPLPipeline 只是一个自定义的流水线步骤,因为它位于 vars 目录中。MPLPipeline 结构非常简单,执行步骤如下:</p>

<ol>
<li>初始化 MPL MPL 使用 MPLManager 单例对象来控制流水线</li>
<li>使用默认值合并配置并将其存储
指定阶段所需的默认配置并预定义一些有用的配置</li>
<li>定义一个包含4个阶段和后续步骤的声明式流水线:

<ol>
<li>检出(Checkout)- 获取项目源代码</li>
<li>构建(Build)- 编译,静态分析,单元测试</li>
<li>部署(Deploy)- 将制品上传到动态环境(dynamic environment)并运行应用程序</li>
<li>测试(Test)- 检查与其他组件的集成</li>
<li>后续步骤(Poststeps)- 清理动态环境,发送通知等</li>
</ol></li>
<li>运行已定义的流水线
这是 MPL 开始发挥其魔法并实际运行的地方</li>
</ol>

<p>MPL 的主要阶段只有一步,即 <a href="https://github.com/griddynamics/mpl/blob/master/vars/MPLModule.groovy#L29">MPLModule</a>。此步骤包含 MPL 的核心特性:执行包含流水线逻辑的模块。你可以在 MPL 代码仓库中找到默认模块,这些模块位于 resources/com/griddynamics/devops/mpl/modules 目录中,包括:Checkout,Build,Deploy 和 Test 模块。在每个模块的目录中,我们都可以找到真正执行相应阶段逻辑的 Groovy 文件。下图是简化了的 MPL 代码仓库结构图:</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
378
<p><img src="fig03-a-simplified-mpl-repository-structure.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438

<p>检出阶段启动时,MPLModule 按名称加载模块(默认为阶段名称),并运行 Checkout/Checkout.groovy 文件中的逻辑:</p>

<pre><code class="language-groovy">if( CFG.'git.url' )
  MPLModule('Git Checkout', CFG)
else
  MPLModule('Default Checkout', CFG)
</code></pre>

<p>如果配置中包含该 git.url 选项,它将加载一个 Git Checkout 模块。否则,它将运行该 Default Checkout 模块。所有被调用的模块使用与父模块相同的配置,这就是 CFG 被传递给 MPLModule 调用的原因。在以上代码中,我们没有指定 git.url 配置,因此它将运行 Checkout/DefaultCheckout.groovy 中的逻辑。模块名称中的空格是将模块映射到特定文件夹的分隔符。</p>

<p>在 Default Checkout 模块中,只有一行代码 checkout scm,它负责克隆 Jenkins 任务中指定的源代码仓库。这就是检出阶段所做的一切,MPL 对于这么小的阶段似乎有些多余,我们只需要在这里讨论它,以展示 MPL 在模块中的工作方式。</p>

<p>当流水线运行 Maven Build 模块时,也是同样的运行逻辑:</p>

<pre><code class="language-groovy">withEnv([&quot;PATH+MAVEN=${tool(CFG.'maven.tool_version' ?: 'Maven 3')}/bin&quot;]) {
  def settings = CFG.'maven.settings_path' ? &quot;-s '${CFG.'maven.settings_path'}'&quot; : ''
  sh &quot;&quot;&quot;mvn -B ${settings} -DargLine='-Xmx1024m -XX:MaxPermSize=1024m' clean install&quot;&quot;&quot;
}
</code></pre>

<p>这个阶段稍微复杂一些,但是操作很简单:我们使用默认名称为 Maven 3 的工具来运行 mvn clean install 命令。这些模块是脚本化的流水线(scripted pipeline),所以你可以执行所有 Jenkins 流水线支持的步骤。这些文件不需要任何特定的和复杂的语法,只需要一个普通的文件,其中包含步骤和 CFG, CFG 是包含了阶段配置的预定义变量。MPL 模块从父模块继承了沙盒(sandbox),因此你的脚本执行将是安全的,并且和一个普通的 Jenkins 流水线一样在 Jenkins 重启后还能生效。</p>

<p>在 Deploy 文件夹中,Openshift Deploy 模块具有相同的结构。它的主要目的中是为了展示如何在模块中定义后续步骤(poststep):</p>

<pre><code class="language-groovy">MPLPostStep('always') {
  echo &quot;OpenShift Deploy Decommission poststep&quot;
}
echo 'Executing Openshift Deploy process'
</code></pre>

<p>首先,我们定义了 always 后续步骤。它最终会被存放到 MPLManager 对象中(译注:<a href="https://github.com/griddynamics/mpl/blob/master/src/com/griddynamics/devops/mpl/MPLManager.groovy#L40),在真正执行后续步骤时被调用。我们可以多次定义">https://github.com/griddynamics/mpl/blob/master/src/com/griddynamics/devops/mpl/MPLManager.groovy#L40),在真正执行后续步骤时被调用。我们可以多次定义</a> always MPLPostStep:所有后续步骤都将按先进后出(FILO)顺序存放和执行。因此,我们可以在同一模块中定义需要完成和撤消操作的后续步骤逻辑,例如动态环境的销毁。这样就可以确保在流水线完成时执行操作。</p>

<p>在部署阶段之后,流水线会执行测试阶段,但是在测试阶段并没有太多有趣的事情发生。然而,测试中有一个非常重要的事情,那就是 MPL 本身的测试。</p>

<h3 id="mpl-本身的测试">MPL 本身的测试</h3>

<p>MPL 的测试框架基于 LesFurets 的 <a href="https://github.com/jenkinsci/JenkinsPipelineUnit">JenkinsPipelineUnit</a>,其中一个很小的区别是它能够测试 MPL 模块。测试整个流水线被认为是不现实的,因为流水线可能非常复杂,为这些怪物编写测试就像一项西西弗斯任务(sisyphean task,译注:永无尽头而又徒劳无功的任务)。而使用用少量的步骤测试一个黑盒要容易得多,可以确保任务能正常工作。</p>

<p>在 MPL 源代码中,你可以找到构建模块的测试用例:所有测试都存放在 test/groovy/com/griddynamics/devops/mpl/modules 目录中,Build/BuildTest.groovy 文件内有多个测试用例。MPL 库的构建阶段会执行这些测试,测试的步骤如下:</p>

<pre><code class="language-groovy">Loading shared library mpl with version snapshot
  MPLModule.call(Build, {maven={tool_version=Maven 2}})
    Build.run()
      Build.MPLModule(Maven Build, {maven.tool_version=Maven 2})
        MavenBuild.run()
          MavenBuild.tool(Maven 2)
          MavenBuild.withEnv([PATH+MAVEN=Maven 2_HOME/bin], groovy.lang.Closure)
            MavenBuild.sh(mvn -B  -DargLine='-Xmx1024m -XX:MaxPermSize=1024m' clean install)
      Build.fileExists(openshift)
</code></pre>

<p>测试运行 MPLModule 自定义配置和模拟步骤,以检查在执行期间,工具是否已根据提供的配置更改为 Maven 2。我们使用此类测试覆盖所有测试用例,确保模块按预期工作,并且流水线将正常工作。如果需要,你可以测试整条流水线,但模块测试是简化测试过程的一种方法。</p>

<p>现在我们已经了解了如何测试 MPL 模块,现在是时候看看 MPL 的一个关键特性,即嵌套库。</p>

<h3 id="嵌套库的好处">嵌套库的好处</h3>

<p>在大型公司中,支持一个大型库是没有意义的。每个部门都需要多个(不同于标准的)配置选项,并针对标准流水线进行调整,这会带来不必要的工作量。MPL 通过引入嵌套库来解决这些问题。下图展示了使用嵌套库与仅仅使用主库的区别:</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
439
<p><img src="fig04-ways-to-use-the-mpl.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
440 441 442

<p>嵌套库与共享库相同,都通过导入 MPL 使用其特性,模块和流水线。此外,它允许将一些与团队相关的逻辑与公司的通用逻辑分离。以下是具有嵌套库的 MPL 的结构:</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
443
<p><img src="fig05-example-of-a-companys-libraries-tree-structure.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
444 445 446 447 448 449 450 451 452 453 454 455 456

<p>你可以在重写的流水线中导入 MPL,指定一些附加模块的路径,覆盖模块逻辑,并由 Jenkins 负责协调(译注:此处原文是You can import the MPL in the overridden pipeline, specify the path of some additional modules, override module
logic, and use Jenkins power moves: there are no limitations. 本人能力有限,无法真正理解作者的意思)。当另一个团队需要你的模块时,你只需向公司 MPL 基础仓库提交变更请求,如果变更请求通过,就可以与他们共享你的功能模块。</p>

<p>因为嵌套库可以覆盖 MPL 或 Jenkins 流水线的基本功能,所以嵌套库可以调试和修改 MPL 提供的步骤(例如 MPLModule)和流水线。你可以覆盖任何功能,因为这些覆盖仅影响你自己的流水线。经常验证的嵌套库,可以与其他团队讨论,看看它是否也适用于其他嵌套库。</p>

<p>嵌套库的嵌套层级数是没有限制的,但我们建议仅使用两层级( MPL 和嵌套库),因为在低层级上配置和测试嵌套库非常复杂。</p>

<h3 id="强大的模块覆盖">强大的模块覆盖</h3>

<p>进一步了解嵌套库和项目端模块后,我们知道,模块名称是可以与上层库中模块名同名的。这是覆盖上层模块逻辑的好方法——使用自己的模块替换
Build/Build.groovy——真正执行时就会执行你的模块中的逻辑,而不是上层模块的。下图说明了模块覆盖是如何工作的:</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
457
<p><img src="fig06-mpl-modules-overriding.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
458 459 460

<p>更棒的是,MPL 的优点之一是你仍然可以使用上层模块!MPL 具有防止循环调用的机制,因此同一运行分支中不会再次运行同一模块。但是,你可以轻松地通过在一个模块中调用原始模块来使用上层逻辑。</p>

LinuxSuRen's avatar
LinuxSuRen 已提交
461
<p><img src="fig07-petclinic-selenium-example-pipeline-structure.png" alt="image.png" /></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532

<p>上面的 Petclinic-Selenium 示例中,使用了默认值 MPLPipeline(您可以在 <a href="https://github.com/griddynamics/mpl/wiki">MPL Wiki</a> 页面上找到它),并在 .jenkins 目录中包含项目级别模块。这些模块将在库模块之前调用。例如,Checkout 模块没有放在项目级别,因此它将从 MPL 调用,但 Build 模块存在于 .jenkins 项目端的目录中,它将被调用:</p>

<pre><code class="language-groovy">MPLPostStep('always') {
  junit 'target/surefire-reports/*.xml'
}

MPLModule('Build', CFG)

if( fileExists('Dockerfile') ) {
  MPLModule('Docker Build', CFG)
}
</code></pre>

<p>如代码所示,项目中的 Build 模块注册了后续步骤,接着调用原始的 Build 模块,最后调用 Docker Build 模块。流水线的后续阶段更复杂,但所有模块覆盖基本原理都相同。现实中,有些项目可能很棘手,需要对现有模块进行一些小调整。但是,你可以在项目级别的模块中轻松调整,并考虑如何将功能移动到嵌套库或 MPL 中。</p>

<h3 id="结论-mpl-为-devops-带来了什么">结论:MPL 为 DevOps 带来了什么</h3>

<p>许多 DevOps 团队和公司都使用臃肿,限制多的的和错误的 CI/CD 自动化平台。这增加了用户的学习曲线,导致团队工作更慢,并提高了生产成本。DevOps 团队发现,相同的问题经常在不同的项目中出现,而缺乏协作意味着团队每次都必须单独修复它们。</p>

<p>但是,通过 MPL,DevOps 团队拥有一个共享、简单、灵活的 CI/CD 平台。可以改善生产过程中的用户支持,协作和整体项目源代码。通过利用 MPL,你的公司可以找到自动化共识,实现跨公司协作的目标,并重用来自大型社区的最佳实践。而且这些都是开源工具。如果你对构建 MPL 感兴趣,请联系我们以了解更多信息!</p>

<h3 id="其他资源">其他资源</h3>

<ul>
<li><a href="https://jenkins.io/doc/book/pipeline/#overview">Jenkins Pipeline Engine</a></li>
<li><a href="https://jenkins.io/doc/book/pipeline/shared-libraries/#extending-with-shared-libraries">Jenkins Shared Libraries</a></li>
<li><a href="https://github.com/griddynamics/mpl">MPL GitHub repository</a></li>
</ul>

<h3 id="概述和演示视频">概述和演示视频:</h3>

<ul>
<li><a href="https://youtu.be/NpnQS3fFlyI">介绍</a></li>
<li><a href="https://youtu.be/wwi7oREL02k">概述</a></li>
<li><a href="https://youtu.be/QZsQThhPk-Y">MPL Build的演示</a></li>
<li><a href="https://youtu.be/UsThHFze76Y">嵌套库的演示</a></li>
<li><a href="https://youtu.be/GLtvxY1S3Aw">流水线的演示</a></li>
</ul>

</div>


<aside class="bt bw1 pt3 mt2 mid-gray b--mid-gray fn w-100">

</aside>




<script src="https://utteranc.es/client.js"
        repo="jenkins-zh/jenkins-zh.github.io"
        issue-term="pathname"
        theme="github-light"
        crossorigin="linuxsuren"
        async>
</script>


          

        </div>
      </div>
      

    </div>
  </article>

  <div class="w-100 bg-light-gray">
    <div class="mw7 pa4 center nested-lh-copy lh-copy">
      <h6 class="f4 dark-gray mb2">
533
  <a href="https://jenkins-zh.github.io/wechat/articles/2019/03/2019-01-08-mpl-modular-pipeline-library/" class="hide-child link primary-color">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
534 535 536
  <span class="nl3 child"><svg class="grow" fill="" height="14px" viewBox="0 0 24 24" width="14px" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>
</span>
    “MPL - 模块化的流水线库”
LinuxSuRen's avatar
LinuxSuRen 已提交
537
  </a> 更新于:March 6, 2019
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
</h6>

      <a href="https://github.com/jenkins-zh/jenkins-zh/edit/master/content/wechat/articles/2019/03/2019-01-08-mpl-modular-pipeline-library.md" class="
f6 ph3 pv1 br2 dib  tc ttu mv3 bg-primary-color white hover-bg-green link
" target="_blank">改善此页</a>

      

  
  
  

  <div class="nested-lh-copy">
    <ul class="list dib nested-links ml0 pl0">
      
        <li class="db mb2 b">
          Tags:
        </li>
        
          <li class="db dib-l mr3">
            <a class="tag" href="/tags/jenkins">
              jenkins
            </a>
          </li>
        
          <li class="db dib-l mr3">
            <a class="tag" href="/tags/pipeline">
              pipeline
            </a>
          </li>
        
          <li class="db dib-l mr3">
            <a class="tag" href="/tags/shared-library">
              shared-library
            </a>
          </li>
        
              
      
        
        
          <li class="db dib-l mb2 mr3">
LinuxSuRen's avatar
LinuxSuRen 已提交
580 581
            <a href="/wechat/articles/2019/08/2019-08-05-jenkins-multi-branch-pipeline/" class="link">
              在大型企业里维护多分支流水线
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
582 583 584 585 586 587 588 589 590 591
            </a>
          </li>
        
      
        
          <li class="db b mt4 mb2 mr2">
            Related entries:
          </li>
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
592 593 594 595 596 597 598 599 600
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/07/2019-07-31-pipeline-config-history-plugin/" class="link">
              Jenkins 流水线配置历史插件介绍
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
601 602 603 604 605 606 607 608 609
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/07/2019-07-14-jenkins-pipeline-workshop/" class="link">
              持续交付落地实践工作坊
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
610 611 612 613 614 615 616 617 618
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/07/2019-07-18-jenkins-weekly-release/" class="link">
              Jenkins 每周版更新
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
619 620 621 622 623 624 625 626 627
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/07/2019-07-09-jenkins-release/" class="link">
              Jenkins 长期支持版更新
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
628 629 630 631 632 633 634 635 636
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/06/2019-06-26-using-active-choices-plugin-merge-jobs/" class="link">
              使用Active-Choices-Plugin插件将十个Job合成一个
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
637 638 639 640 641 642 643 644 645
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/06/2019-06-14-setup-jenkins-ci-in-30-minutes/" class="link">
              30分钟搞定 Jenkins CI
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
646 647 648 649 650 651 652 653 654
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/06/2019-06-10-jenkins-pipeline-workshop/" class="link">
              还在苦恼不会写 Jenkins 流水线?来场工作坊!
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
655 656 657 658 659 660 661 662 663
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-29-jenkins-release/" class="link">
              Jenkins 2.176~2.178版本更新
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
664 665 666 667 668 669 670 671 672
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-28-jenkins-pipeline-shared-lib-unit-test/" class="link">
              如何对 Jenkins 共享库进行单元测试
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
673 674 675 676 677 678 679 680 681
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-22-jacoco-coverage-for-functional-test/" class="link">
              基于 Jenkins &#43; JaCoCo 实现功能测试代码覆盖率统计
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
682 683 684 685 686 687 688 689 690
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-20-jenkins-ansible-springboot/" class="link">
              使用 Jenkins &#43; Ansible 实现 Spring Boot 自动化部署101
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
691 692 693 694 695 696 697 698 699
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-17-from-jenkins-to-jenkins-x/" class="link">
              从 Jenkins 到 Jenkins X
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
700 701 702 703 704 705 706 707 708
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-15-gsoc-annoncement/" class="link">
              19年 GSoC 中 Jenkins 的七个项目
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
709 710 711 712 713 714 715 716 717
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-14-devops-jenkins-credential-manage/" class="link">
              基于 Jenkins 的 DevOps 平台应该如何设计凭证管理
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
718 719 720 721 722 723 724 725 726
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-13-jenkins-book-gift/" class="link">
              Jenkins 公众号送书福利
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
727 728 729 730 731 732 733 734 735
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-09-jenkins-release/" class="link">
              Jenkins 版本发布
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
736 737 738 739 740 741 742 743 744
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-08-jenkins-plugin-develop-within-two-days-part02/" class="link">
              Jenkins 插件开发之旅:两天内从 idea 到发布(下篇)
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
745 746 747 748 749 750 751 752 753
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-07-jenkins-install-plugins-shell/" class="link">
              Jenkins 自动化安装插件
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
754 755 756 757 758 759 760 761 762
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/05/2019-05-06-jenkins-plugin-develop-within-two-days-part01/" class="link">
              Jenkins 插件开发之旅:两天内从 idea 到发布(上篇)
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
763 764 765 766 767 768 769 770 771
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-29-progressive-delivery-with-jenkins-x-automatic-cana/" class="link">
              使用 Jenkins X 渐进式交付:自动化金丝雀部署
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
772 773 774 775 776 777 778 779 780
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-26-progressive-delivery-with-jenkins-x/" class="link">
              使用 Jenkins X 渐进式交付
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
781 782 783 784 785 786 787 788 789
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-25-jenkins-ansible-nginx/" class="link">
              使用 Jenkins &#43; Ansible 实现自动化部署 Nginx
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
LinuxSuRen 已提交
790 791 792 793 794 795 796 797 798
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-23-jenkins-master-shared-home/" class="link">
              关于 Jenkins master 共享 JENKINS_HOME 目录的实验
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
799 800 801 802 803 804 805 806 807
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-19-the-business-value-of-cd/" class="link">
              持续交付的商业价值
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
808 809 810 811 812 813 814 815 816
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-15-zabbix-monitor-jenkins/" class="link">
              使用 Zabbix 监控 Jenkins
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
817 818 819 820 821 822 823 824 825
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-12-brief-analysis-the-encryption-algorithm-of-the-built-in-jenkins-user-database/" class="link">
              简析 Jenkins 专有用户数据库加密算法
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
826 827 828 829 830 831 832 833 834
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-10-getting-started-with-docker-for-java-applications/" class="link">
              Java 应用使用 Docker 的入门指南:建立一个 CI/CD 流水线
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/04/2019-04-08-becoming-contributor-intro/" class="link">
              介绍:成为一名 Jenkins 贡献者的旅程
            </a>
          </li>
        
      
        
        
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/03/2019-03-13-electron-pipeline-demo/" class="link">
              Electron 应用的流水线设计
            </a>
          </li>
        
      
        
        
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/03/2019-03-13-ready-for-cdf/" class="link">
              为 Continuous Delivery Foundation 的成立感到兴奋
            </a>
          </li>
        
      
        
        
      
        
        
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/02/2019-02-27-jenkins-script-console-in-practice/" class="link">
              批量修改 Jenkins 任务的技巧
            </a>
          </li>
        
      
        
        
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/01/2019-01-16-webhook-firewalls/" class="link">
              在安全防火墙内通过 WebHook 触发构建
            </a>
          </li>
        
      
LinuxSuRen's avatar
LinuxSuRen 已提交
881 882 883 884 885 886 887 888 889
        
        
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/06/2019-06-24-becoming-contributor-newbie-tickets/" class="link">
              成为一名 Jenkins 贡献者:对新手友好的工单
            </a>
          </li>
        
      
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
890 891 892 893 894 895 896 897
    </ul>
  </div>


    </div>
  </div>
</main>

LinuxSuRen's avatar
LinuxSuRen 已提交
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
<script type="text/javascript">
if(window.location.search == "?copy=true") {
  showCopyBut();
}

function copyMe(){
  var tempElements = [];

  var logoZone = document.createElement("div");
  logoZone.innerHTML = "<a href=\"https://jenkins-zh.cn\"><img width=\"520\" src=\"https://jenkins-zh.cn/wechat/images/grey-backgroud-jenkins-slogan.jpg\"/></a>";
  document.getElementById('prose').append(logoZone);
  tempElements.push(logoZone);
  var doc = document.getElementsByClassName('documentation-copy')[0];

  var articleHeader = document.createElement("div");
  tempElements.push(articleHeader);
914
  articleHeader.innerHTML = "本文首发于:<a href=\"https:\/\/jenkins-zh.github.io\/wechat\/articles\/2019\/03\/2019-01-08-mpl-modular-pipeline-library\/\">Jenkins 中文社区</a>";
LinuxSuRen's avatar
LinuxSuRen 已提交
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983

  
  var rangeToSelect = document.createRange();
  rangeToSelect.selectNodeContents(doc);

  var data = window.getSelection();
  data.addRange(rangeToSelect);

  tempElements.push(appendArticleFooter(data.getRangeAt(0)));
  data.getRangeAt(0).insertNode(articleHeader);
  document.execCommand("copy", true, null);

  
  for(var i in tempElements) {
    tempElements[i].remove();
  }
  clearSelection();

  hideCopyBut();
}

function clearSelection(){
  window.getSelection().empty();
}

function showCopyBut() {
  document.getElementById('copyMe').style="";
}

function hideCopyBut() {
  document.getElementById('copyMe').style="display:none";
}

function appendArticleFooter(range) {
  var articleFooter = createArticleFooter();
  range.insertNode(articleFooter);
  return articleFooter;
}

function createArticleFooter() {
  var articleFooter = document.createElement("div");
  var authors = document.getElementsByClassName("author");
  var originalAuthors = document.getElementsByClassName("originalAuthor");
  var originalLinks = document.getElementsByClassName("originalLink");
  var articleFooterHtml = "";
  var isTranslated = false;
  if(originalAuthors.length > 0){
    articleFooterHtml += "<div>";
    if(originalLinks.length > 0){
      articleFooterHtml += "<a href=" + originalLinks[0].innerText + ">原文链接</a>&nbsp;&nbsp;&nbsp;&nbsp;";
    }
    articleFooterHtml += "作者:" + originalAuthors[0].innerText;
    articleFooterHtml += "</div>";
    isTranslated = true;
  }
  if(authors.length > 0){
    articleFooterHtml += "<div>";
    if(isTranslated) {
      articleFooterHtml += "译者:" + authors[0].innerText;
    } else {
      articleFooterHtml += "作者:" + authors[0].innerText;
    }
    articleFooterHtml += "</div>";
  }
  articleFooter.innerHTML = articleFooterHtml;
  return articleFooter;
}
</script>

LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
984 985 986 987 988 989 990
    </main>

    <footer class="bg-primary-color-dark ph4-ns pt4 relative w-100" role="contentinfo">
  <div class="center flex-ns flex-wrap justify-between mw9 w-90">
    <div class="pb3 pt4 w-100 w-50-ns">

      <div class="b f3  light-gray mb3 nested-links tc">
991 992
<a href="https://github.com/jenkins-zh/jenkins-zh/graphs/contributors" target="_blank"
          class="link">Jenkins 社区贡献者</a> 维护<br />
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
993 994 995 996 997 998
      </div>

      <ul class="center f6 list ma0 mv3 pa0 tc" style="display:none"><li class="dib mr3"><a href="https://github.com/jenkins-zh/jenkins-zh/issues/new" class="dim link light-gray pv2">File an Issue</a></li></ul>

      <ul class="center f6 list ma0 mv4 pa0 tc">
        <li class="dib mr3">
LinuxSuRen's avatar
LinuxSuRen 已提交
999
          <a href="https://twitter.com/jenkinsci" target="_blank" class="dim link light-gray pv2">Twitter</a>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1000 1001
        </li>
        <li class="dib mr3">
1002 1003
          <a href="https://www.youtube.com/channel/UC63xz3pq26BBgwB3cnwCoqQ" target="_blank"
            class="dim link light-gray pv2">YouTube</a>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1004
        </li>
LinuxSuRen's avatar
LinuxSuRen 已提交
1005 1006 1007
        <li class="dib mr3">
          <a href="https://space.bilibili.com/433584098" target="_blank" class="dim link light-gray pv2">哔哩哔哩</a>
        </li>
1008
        <li class="dib mr3">
1009
          <a href="http://jcli.jenkins-zh.cn/" target="_blank" class="dim link light-gray pv2">Jenkins
1010 1011
            CLI</a>
        </li>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1012 1013 1014 1015 1016 1017
      </ul>

      
    </div>

    <div>
1018 1019 1020 1021 1022
      <div style="color: #ffffff; display: inline-block; text-align: center; margin-right: 5px; margin-left: 5px;">优酷视频
        <div>
          <a href="https://i.youku.com/jenkinszh" target="_blank">
            <img src="/images/youku-qrcode.png" with="100" height="100">
          </a>
LinuxSuRen's avatar
LinuxSuRen 已提交
1023
        </div>
1024 1025 1026 1027 1028 1029
      </div>
      <div style="color: #ffffff; display: inline-block; text-align: center; margin-right: 5px; margin-left: 5px;">微信公众号
        <div>
          <a href="https://mp.weixin.qq.com/s/vifdduC3kRGSIMpyL03yVA" target="_blank">
            <img src="https://jenkins.io/images/jenkins-wechat.png" with="100" height="100">
          </a>
LinuxSuRen's avatar
LinuxSuRen 已提交
1030 1031
        </div>
      </div>
1032
    </div>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1033 1034 1035 1036

  </div>

  <div class="f7 gray mb5 mb0-ns ph3 w-100" style="display:none"> 
1037 1038
    <p class="dib mr4">Jenkins&reg; is a registered trademark of <a href="https://www.spi-inc.org/"
        class="link">Software in the Public Interest, Inc.</a></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
    <p class="dib">Copyright 2018–2019 the original authors.</p>
  </div>


  <div class="bg-primary-color-dark bottom-0 left-0 right-0 dn-l fixed pb3 ph3 w-100"><div  class="globalmenu mobilemenu pb3 dn">
    

<ul class="list hidden dib ph0 ma0 scrolling-touch tc">
  
    <li  class="tl dib ma0 hover-bg-black w-100">
        <a href="/wechat/" class="ttu f6 link primary-color-light overflow hover-white db brand-font  ma0 w-100 pv3 ph4">
LinuxSuRen's avatar
LinuxSuRen 已提交
1050
          博客
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1051 1052 1053
        </a>
    </li>
  
LinuxSuRen's avatar
LinuxSuRen 已提交
1054 1055 1056 1057 1058 1059
    <li  class="tl dib ma0 hover-bg-black w-100">
        <a href="/tutorial/" class="ttu f6 link primary-color-light overflow hover-white db brand-font  ma0 w-100 pv3 ph4">
          教程
        </a>
    </li>
  
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1060 1061 1062 1063 1064 1065 1066
    <li  class="tl dib ma0 hover-bg-black w-100">
        <a href="/event/" class="ttu f6 link primary-color-light overflow hover-white db brand-font  ma0 w-100 pv3 ph4">
          活动
        </a>
    </li>
  
    <li  class="tl dib ma0 hover-bg-black w-100">
LinuxSuRen's avatar
LinuxSuRen 已提交
1067 1068 1069 1070 1071 1072
        <a href="/partner/" class="ttu f6 link primary-color-light overflow hover-white db brand-font  ma0 w-100 pv3 ph4">
          合作伙伴
        </a>
    </li>
  
    <li  class="tl dib ma0 hover-bg-black w-100">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
        <a href="/about/" class="ttu f6 link primary-color-light overflow hover-white db brand-font  ma0 w-100 pv3 ph4">
          关于我们
        </a>
    </li>
  
    <li  class="tl dib ma0 hover-bg-black w-100">
        <a href="http://jenkins.io/zh" class="ttu f6 link primary-color-light overflow hover-white db brand-font  ma0 w-100 pv3 ph4">
          Jenkins 官网
        </a>
    </li>
  
</ul>

</div>


<div class="flex dn-l justify-between">
LinuxSuRen's avatar
LinuxSuRen 已提交
1090
  <button class="js-toggle flex-auto dib dn-l f6 tc db mt4-ns ph3 pv2 link mr2 white bg-primary-color-dark hover-bg-primary-color ba b--white-40 w-auto" data-target=".globalmenu">菜单</button>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1091

LinuxSuRen's avatar
LinuxSuRen 已提交
1092
  
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1093
</div>
LinuxSuRen's avatar
LinuxSuRen 已提交
1094
<script src="/dist/app.bundle.js" type="text/javascript"></script>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1095 1096
</div>

1097 1098 1099 1100 1101 1102
  <script>
    ((window.gitter = {}).chat = {}).options = {
      room: 'jenkinsci/chinese'
    };
  </script>
  <script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1103 1104 1105 1106 1107 1108
</footer>

    
<link href="/dist/auto-complete.css" rel="stylesheet">
<script type="text/javascript">
    
1109
        var baseurl = "https:\/\/jenkins-zh.github.io";
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1110 1111 1112 1113 1114 1115 1116 1117
    
</script>
<script src="/dist/lunr.js"></script>
<script src="/dist/autocomplete.js"></script>
<script src="/dist/jquery-3.2.1.min.js"></script>
<script src="/dist/search.js"></script>

<script async defer src="https://buttons.github.io/buttons.js"></script>
LinuxSuRen's avatar
LinuxSuRen 已提交
1118 1119 1120 1121 1122 1123 1124 1125 1126
<script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?6db234f713318730f0e5f6a95bdd8d47";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
</script>
LinuxSuRen's avatar
LinuxSuRen 已提交
1127 1128 1129 1130 1131 1132 1133
<script>
(function(){
var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?6276dcef5c15f276644151772390c1f9":"https://jspassport.ssl.qhimg.com/11.0.1.js?6276dcef5c15f276644151772390c1f9";
document.write('<script src="' + src + '" id="sozz"><\/script>');
})();
</script>

LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1134 1135 1136

  </body>
</html>