index.html 36.2 KB
Newer Older
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
1 2 3
<!DOCTYPE html>
<html class="no-js" lang="zh-CN">

4 5 6 7 8 9
<head>
  <meta charset="utf-8">
  
  <link rel="preload" href="https://jenkins-zh.cn/files/muli-latin-200.woff2" as="font" type="font/woff2" crossorigin>
  <link rel="preload" href="https://jenkins-zh.cn/files/muli-latin-400.woff2" as="font" type="font/woff2" crossorigin>
  <link rel="preload" href="https://jenkins-zh.cn/files/muli-latin-800.woff2" as="font" type="font/woff2" crossorigin>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  
  <title>介绍新的 GitLab 分支源插件 - Jenkins 中文社区</title>
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  
  <meta name="description" content="新的 GitLab 分支源插件,允许您基于 GitLab `用户` 或 `组` 或 `子组` 项目创建任务">
  
  
  <meta name="keywords" content="GitLab 分支源插件">
  

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

26 27 28 29 30 31 32 33 34 35 36
  
  <META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
  

  <link href='/dist/main.css' rel='stylesheet' type="text/css" /><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link href="/images/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link rel="icon" type="image/png" href="/images/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/images/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#0594cb">
<meta name="theme-color" content="#ffffff"><style>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
37 38 39 40 41 42 43 44
  img.avatar {
    width: 32px;
    display: inline;
  }
</style>
<meta property="og:title" content="介绍新的 GitLab 分支源插件" />
<meta property="og:description" content="新的 GitLab 分支源插件,允许您基于 GitLab `用户` 或 `组` 或 `子组` 项目创建任务" />
<meta property="og:type" content="article" />
45 46 47
<meta property="og:url" content="https://jenkins-zh.cn/wechat/articles/2019/09/2019-09-11-introducing-gitlab-branch-source-plugin/" /><meta property="article:published_time" content="2019-09-11T00:00:00&#43;00:00"/>
<meta property="article:modified_time" content="2019-09-11T00:00:00&#43;00:00"/>

LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<meta itemprop="name" content="介绍新的 GitLab 分支源插件">
<meta itemprop="description" content="新的 GitLab 分支源插件,允许您基于 GitLab `用户` 或 `组` 或 `子组` 项目创建任务">


<meta itemprop="datePublished" content="2019-09-11T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2019-09-11T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="561">



<meta itemprop="keywords" content="gitlab,plugins,pipeline,multibranch,gsoc,gsoc2019," />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="介绍新的 GitLab 分支源插件"/>
<meta name="twitter:description" content="新的 GitLab 分支源插件,允许您基于 GitLab `用户` 或 `组` 或 `子组` 项目创建任务"/>

63
  
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
<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>

86 87 88 89 90
  
</head>

<body class="ma0 sans-serif bg-primary-color-light">
  
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
91 92 93 94 95
<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">
96
      <a href="https://jenkins-zh.cn" class="link white">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 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
         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"
            >
            博客
              
            
          </a>
        </li>
      
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/tutorial/" class="dim link light-silver"
            >
            教程
              
            
          </a>
        </li>
      
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/event/" class="dim link light-silver"
            >
            活动
              
            
          </a>
        </li>
      
        <li class="f5 dib mr4" role="menuitem">
            
            
          <a href="/partner/" class="dim link light-silver"
            >
            合作伙伴
              
            
          </a>
        </li>
      
        <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>

195 196
  
  <main role="main" class="content-with-sidebar min-vh-100 pb7 pb0-ns">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
    
<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">
    
    
      
        <h3 class="f4 dib author">
214
            Wang Donghui
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
        </h3>

      
      
      <a href="https://github.com/donhui" target="_blank" class="link dim v-mid dib">
        <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>

  
  <div>
    作者:<span class="originalAuthor">baymac</span>
    <div>
      <a class="originalLink" href="" target="_blank">原文链接</a>
    </div>
  </div>
  
  </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">
	
239
		<p class="b">内容目录</p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  	<nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#要求">要求</a></li>
<li><a href="#创建任务">创建任务</a></li>
<li><a href="#创建多分支流水线任务">创建多分支流水线任务</a>
<ul>
<li><a href="#创建-gitlab-组类型任务">创建 GitLab 组类型任务</a></li>
<li><a href="#gitlab-流水线状态通知">GitLab 流水线状态通知</a></li>
<li><a href="#合并请求">合并请求</a></li>
</ul></li>
<li><a href="#hook">Hook</a></li>
<li><a href="#job-dsl-以及-jcasc">Job DSL 以及 JCasC</a></li>
<li><a href="#如何与我们讨论-bug-或新特性">如何与我们讨论 bug 或新特性?</a></li>
<li><a href="#未来的工作">未来的工作</a></li>
<li><a href="#资源">资源</a></li>
</ul></li>
</ul>
</nav>
	

	<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>
		
		
272
			<a href="https://jenkins-zh.cn/wechat/articles/2019/09/2019-09-16-jenkins-world-contributor-summit-and-ask-the-experts-booth/" class="dib f6 pl1 hover-bg-light-gray br-100" title="Jenkins World 贡献者峰会及专家答疑展位 ">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
273 274 275 276 277 278 279
				<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>
		
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
280 281

		
282
			<a href="https://jenkins-zh.cn/wechat/articles/2019/09/2019-09-05-award/" class="dib f6 pr1 hover-bg-light-gray br-100" title="Jenkins 中文社区第二届明星贡献者名单">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
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 339 340 341 342 343 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 378 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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 533 534 535 536 537 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 580 581 582 583 584 585 586 587 588 589 590 591 592
			<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;">
        <button id="copyMe" onclick="copyMe()" style="display: none">Copy Me</button>
        <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">介绍新的 GitLab 分支源插件</h1>
</header>

<aside class="bt bw1 pt3 mt2 mid-gray b--mid-gray fn w-100">
  
    <div class="f4 fw4 lh-copy">
      新的 GitLab 分支源插件,允许您基于 GitLab <code>用户</code><code></code><code>子组</code> 项目创建任务
    </div>
  

  
</aside>



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



<p><img src="gitlab_and_jenkins.png" alt="gitlab_and_jenkins" /></p>

<p>GitLab 分支源插件已经走出 beta 阶段,并已发布到 Jenkins 更新中心。
它允许您基于 GitLab <code>用户</code><code></code><code>子组</code> 项目创建任务。
您可以:</p>

<ul>
<li>从 GitLab 用户/组/子组导入单个项目的分支作为任务(多分支流水线任务)</li>
<li>从 GitLab 用户/组/子组导入所有或部分项目的分支作为任务(GitLab 组任务或 GitLab 文件夹组织)</li>
</ul>

<p>GitLab 组项目对项目进行扫描, 根据设置的规则导入流水线任务。
导入项目之后, Jenkins 立即基于 <code>Jenkinsfile</code> 流水线脚本运行任务并且将状态通知到 GitLab 流水线状态。
这个插件与其他分支源插件不同,它提供了 GitLab 服务器配置,可以在系统配置中配置。
Jenkins 配置即代码 (JCasC) 也可以用于配置服务器。
要想了解更多关于服务器配置的信息,请参考我<a href="https://jenkins.io/zh/blog/2019/08/23/introducing-gitlab-branch-source-plugin/">之前的博客</a></p>

<h2 id="要求">要求</h2>

<ul>
<li><p>Jenkins - 2.176.2 (LTS)</p></li>

<li><p>GitLab - v11.0+</p></li>
</ul>

<h2 id="创建任务">创建任务</h2>

<p>要创建多分支流水线任务(使用 GitLab 分支源)或 GitLab 组任务,您必须将 GitLab 个人访问令牌添加到服务端配置。
凭据用于获取项目的元数据,并在 GitLab 服务器上设置 hook。
如果令牌具有管理访问权限,您还可以设置 <code>系统 Hook</code>,而 <code>Web Hook</code> 可以从任何用户令牌设置。</p>

<h2 id="创建多分支流水线任务">创建多分支流水线任务</h2>

<p>转到 Jenkins &gt; 新建任务 &gt; 多分支流水线 &gt; 添加源 &gt; GitLab 项目</p>

<p><img src="branch-source.png" alt="GitLab Project Branch Source" /></p>

<ul>
<li><p><code>Server</code> - 从下拉菜单中选择所需的 GitLab 服务器,需要在创建此任务之前进行配置。</p></li>

<li><p><code>Checkout Credentials</code> - 如果插件要构建任何私有项目,添加 <code>SSHPrivateKey</code><code>用户名/密码</code> 类型的凭据。如果所有的项目都是公开的则不需要检出凭据。检出凭据与 GitLab 服务器配置中的凭据(<code>GitLab 个人访问令牌</code> 类型)不同。</p></li>

<li><p><code>Owner</code> - 可以是 <code>用户</code><code></code><code>子组</code>。 根据这一点填充 <code>Projects</code> 字段。</p></li>

<li><p><code>Projects</code> - 从下拉菜单中选择要构建的项目。</p></li>

<li><p><code>Behaviours</code> - 这些特性是非常强大的工具,用于配置构建逻辑和构建后逻辑。我们定义了新的特性。您可以在仓库文档中看到所有信息。</p></li>
</ul>

<p>保存并等待分支索引。您可以从这里自由导航,任务进度显示在左侧。</p>

<p><img src="multibranch-indexing.png" alt="Multibranch Pipeline Job Indexing" /></p>

<p>索引完成后,导入的项目将所有分支、合并请求和标签列示为任务。</p>

<p><img src="multibranch-folder.png" alt="Multibranch Pipeline Job Folder" /></p>

<p>查看每个任务,您会发现左侧有一些操作项:</p>

<ul>
<li>您可以通过选择 <code>立即构建</code> 手动触发任务。</li>
<li>您可以通过选择相应的按钮访问 GitLab 服务器上的特定分支/合并请求/标签。</li>
</ul>

<p><img src="icon-tag.png" alt="Build Actions" /></p>

<h3 id="创建-gitlab-组类型任务">创建 GitLab 组类型任务</h3>

<p>转到 Jenkins &gt; 新建任务 &gt; GitLab Group</p>

<p><img src="gitlab-group.png" alt="GitLab Folder Organization" /></p>

<p>您可以注意到,配置非常类似于多分支流水线任务,只是缺少 <code>Projects</code> 字段。
您可以添加在您的 Owner(用户/组/子组)中所有项目。
表单验证将与 GitLab 服务器检查 owner 是否有效。
您可以添加 <code>Discover subgroup project</code> 的特性,该特性允许您发现组或子组中所有子组的子项目,但此特性不适用于用户。
在索引时,web hook 在每个项目中创建。
GitLab Api 不支持创建组 web hook,所以这个插件不支持只有 GitLab EE 才支持的特性。</p>

<p>现在可以查看导入的项目,如果需要,可以在每个文件夹上配置不同的设置。</p>

<p><img src="gitlab-group-folder.png" alt="GitLab Group Folder" /></p>

<h3 id="gitlab-流水线状态通知">GitLab 流水线状态通知</h3>

<p>GitLab 从任务排队的角度得到关于构建状态的通知。</p>

<ul>
<li>成功 - 任务成功了</li>
<li>失败 - 任务失败了并且合并请求还没准备好合并</li>
<li>出错 - 发生了意外;例如:Jenkins 任务被终止了</li>
<li>等待 - 任务正在构建队列中等待</li>
</ul>

<p><img src="pipeline-status.png" alt="GitLab Pipeline Status" /></p>

<p>关于 GitLab 流水线状态,有指向相应 Jenkins 任务构建的超链接。
要查看流水线阶段和控制台输出,需要访问 Jenkins 服务器。
我们也计划通知管道阶段到 GitLab,但它有一些缺点,目前这已得到解决,有未来的计划添加它作为特性。</p>

<p>您还可以通过从特性列表中选择 <code>Skip pipeline status notifications</code> 来跳过关于流水线状态的 GitLab 通知。</p>

<h3 id="合并请求">合并请求</h3>

<p>实现对项目合并请求的支持具有挑战性。
第一,MR 有两种类型,即原始分支和 Fork 的项目分支,因此每个 head 必须有不同的实现。
第二,来自 fork 的 MR 可能来自不可信的源,所以实现了一种新的策略 <code>Trust Members</code>,它允许 CI 仅从具有 <code>Developer</code>/<code>Maintainer</code>/<code>Owner</code> 访问级别的可信用户构建 MR。</p>

<p><img src="trusted-members.png" alt="Trusted Member Strategy" /></p>

<p>第三,来自 fork 的 MR 由于 GitLab 的问题不支持流水线状态通知,请参考<a href="https://docs.gitlab.com/ee/ci/merge_request_pipelines/#important-notes-about-merge-requests-from-forked-projects">这里</a>
您可以添加一个特性 <code>Log Build Status as Comment on GitLab</code> ,它允许那您添加一个 sudo 用户(如果你希望 owner 用户为空)以在 commit/tag/mr 上对构建结果进行评论。
要添加 sudo 用户,令牌必须具有管理访问权限。
默认情况下,只有失败/出错以评论的形式被记录,但是您也可以通过勾选复选框来启用成功构建的日志记录。</p>

<p><img src="log-comment-trait.png" alt="Build Status Comment Trait" /></p>

<p>有时候,合并请求因为外部错误而失败,因此因此您希望通过评论 <code>jenkins rebuild</code> 来触发 mr 的重新构建。
要启用该触发器,添加特性 <code>Trigger build on merge request comment</code>
评论内容可以在特性中修改。
出于安全原因,评论者需要有该项目的 <code>Developer</code>/<code>Maintainer</code>/<code>Owner</code> 访问权限。</p>

<p><img src="build-trigger-trait.png" alt="Merge request build trigger" /></p>

<h2 id="hook">Hook</h2>

<p>如果在服务器配置中配置了 web hook,则在项目上自动创建 web hook。
请确保 web hook 通过 CSRF 过滤器。
Jenkins 监听 <code>/gitlab-webhook/post</code> 路径上的 web hook 。
GitLab 上 web hook 在以下事件上被触发:</p>

<ul>
<li><p><code>Push Event</code> - 当提交或分支被推送时</p></li>

<li><p><code>Tag Event</code> - 当新标签被创建时</p></li>

<li><p><code>Merge Request Event</code> - 当合并请求被创建/更新</p></li>

<li><p><code>Note Event</code> - 当对合并请求进行评论时</p></li>
</ul>

<p>如果令牌具有管理访问权限,还可以在 GitLab 服务器上设置系统 Hook。
在创建新项目时触发系统 hook,Jenkins 根据配置触发新项目的重新扫描,并在其上设置 web hook。
Jenkins 监听 <code>/gitlab-systemhook/post</code> 路径上你的系统 hook。
GitLab 上系统 hook 在 <code>Repository Update Events</code> 上被触发:</p>

<p>你也可以使用 <code>Override Hook Management mode</code> 特性来覆盖默认你的 hook 管理以及选择是否要使用不同的上下文(比如 Item)或完全禁用它。</p>

<p><img src="override-hook.png" alt="Override Hook Management" /></p>

<h2 id="job-dsl-以及-jcasc">Job DSL 以及 JCasC</h2>

<p>你可以使用 <code>Job DSL</code> 来创建任务。
下面有一个 Job DSL 脚本的示例:</p>

<pre><code>organizationFolder('GitLab Organization Folder') {
    description(&quot;GitLab org folder created with Job DSL&quot;)
    displayName('My Project')
    // &quot;Projects&quot;
    organizations {
        gitLabSCMNavigator {
            projectOwner(&quot;baymac&quot;)
            credentialsId(&quot;i&lt;3GitLab&quot;)
            serverName(&quot;gitlab-3214&quot;)
            // &quot;Traits&quot; (&quot;Behaviours&quot; in the GUI) that are &quot;declarative-compatible&quot;
            traits {
                subGroupProjectDiscoveryTrait() // discover projects inside subgroups
                gitLabBranchDiscovery {
                    strategyId(3) // discover all branches
                }
                originMergeRequestDiscoveryTrait {
                    strategyId(1) // discover MRs and merge them with target branch
                }
                gitLabTagDiscovery() // discover tags
            }
        }
    }
    // &quot;Traits&quot; (&quot;Behaviours&quot; in the GUI) that are NOT &quot;declarative-compatible&quot;
    // For some 'traits, we need to configure this stuff by hand until JobDSL handles it
    // https://issues.jenkins.io/browse/JENKINS-45504
    configure { 
        def traits = it / navigators / 'io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator' / traits
        traits &lt;&lt; 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait' {
            strategyId(2)
            trust(class: 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$TrustPermission')
        }
    }
    // &quot;Project Recognizers&quot;
    projectFactories {
        workflowMultiBranchProjectFactory {
            scriptPath 'Jenkinsfile'
        }
    }
    // &quot;Orphaned Item Strategy&quot;
    orphanedItemStrategy {
        discardOldItems {
            daysToKeep(10)
            numToKeep(5)
        }
    }
    // &quot;Scan Organization Folder Triggers&quot; : 1 day
    // We need to configure this stuff by hand because JobDSL only allow 'periodic(int min)' for now
    triggers {
        periodicFolderTrigger {
            interval('1d')
        }
    }
}
</code></pre>

<p>你也可以使用 <code>JCasC</code> 从 Job DSL 脚本直接创建任务。示例请查看该插件<a href="https://github.com/jenkinsci/gitlab-branch-source-plugin/blob/develop/README.md">仓库</a></p>

<h2 id="如何与我们讨论-bug-或新特性">如何与我们讨论 bug 或新特性?</h2>

<ul>
<li><p>这个项目使用 <a href="https://issues.jenkins-ci.org/">Jenkins JIRA</a> 来跟踪问题。 你可以查看 <a href="https://issues.jenkins-ci.org/issues/?jql=project+%3D+JENKINS+AND+component+%3D+gitlab-branch-source-plugin"><code>gitlab-branch-source-plugin</code></a> 组件下面的问题。</p></li>

<li><p><a href="https://groups.google.com/forum/#!forum/jenkinsci-dev">开发者邮件列表</a>中发送你的邮件。</p></li>

<li><p>加入我们的 <a href="https://gitter.im/jenkinsci/gitlab-branch-source-plugin">Gitter channel</a></p></li>
</ul>

<h2 id="未来的工作">未来的工作</h2>

<ul>
<li>积极维护 <code>GitLab 分支源插件</code> 并从用户那里获取反馈以改进插件的用户体验。</li>
<li>扩展在 BlueOcean 中对 GitLab 流水线的支持。</li>
</ul>

<h2 id="资源">资源</h2>

<ul>
<li><a href="https://github.com/jenkinsci/gitlab-api-plugin">GitLab API 插件</a></li>
<li><a href="https://wiki.jenkins.io/display/JENKINS/GitLab+API+Plugin">GitLab API 插件 Wiki</a></li>
<li><a href="https://github.com/jenkinsci/gitlab-branch-source-plugin">GitLab 分支源插件</a></li>
<li><a href="https://jenkins.io/projects/gsoc/2019/gitlab-support-for-multibranch-pipeline/">项目概要</a></li>
<li><a href="https://go.cloudbees.com/docs/plugins/github-branch-source/">GitHub 分支源插件发布</a></li>
</ul>

<p>感谢 Jenkins 以及 Google 编程夏令营 :)</p>

</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">
593
  <a href="https://jenkins-zh.cn/wechat/articles/2019/09/2019-09-11-introducing-gitlab-branch-source-plugin/" class="hide-child link primary-color">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
594 595 596 597 598 599 600 601
  <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>
    “介绍新的 GitLab 分支源插件”
  </a> 更新于:September 11, 2019
</h6>

      <a href="https://github.com/jenkins-zh/jenkins-zh/edit/master/content/wechat/articles/2019/09/2019-09-11-introducing-gitlab-branch-source-plugin.md" class="
f6 ph3 pv1 br2 dib  tc ttu mv3 bg-primary-color white hover-bg-green link
602
" target="_blank">完善此页</a>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694

      

  
  
  

  <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/gitlab">
              gitlab
            </a>
          </li>
        
          <li class="db dib-l mr3">
            <a class="tag" href="/tags/plugins">
              plugins
            </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/multibranch">
              multibranch
            </a>
          </li>
        
          <li class="db dib-l mr3">
            <a class="tag" href="/tags/gsoc">
              gsoc
            </a>
          </li>
        
          <li class="db dib-l mr3">
            <a class="tag" href="/tags/gsoc2019">
              gsoc2019
            </a>
          </li>
        
              
      
        
        
      
        
          <li class="db b mt4 mb2 mr2">
            Related entries:
          </li>
        
        
          <li class="db dib-l mb2 mr3">
            <a href="/wechat/articles/2019/07/2019-07-10-phase-1-multibranch-pipeline-support-for-gitlab/" class="link">
              多分支流水线任务对 GitLab SCM 的支持
            </a>
          </li>
        
      
    </ul>
  </div>


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

<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);
695
  articleHeader.innerHTML = "本文首发于:<a href=\"https:\/\/jenkins-zh.cn\/wechat\/articles\/2019\/09\/2019-09-11-introducing-gitlab-branch-source-plugin\/\">Jenkins 中文社区</a>";
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764

  
  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>

765
  </main>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
766

767
  <footer class="bg-primary-color-dark ph4-ns pt4 relative w-100" role="contentinfo">
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
768 769 770 771
  <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">
772 773
<a href="https://github.com/jenkins-zh/jenkins-zh/graphs/contributors" target="_blank"
          class="link">Jenkins 社区贡献者</a> 维护<br />
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
774 775 776 777 778 779 780 781 782
      </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">
          <a href="https://twitter.com/jenkinsci" target="_blank" class="dim link light-gray pv2">Twitter</a>
        </li>
        <li class="dib mr3">
783 784
          <a href="https://www.youtube.com/channel/UC63xz3pq26BBgwB3cnwCoqQ" target="_blank"
            class="dim link light-gray pv2">YouTube</a>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
785 786 787 788
        </li>
        <li class="dib mr3">
          <a href="https://space.bilibili.com/433584098" target="_blank" class="dim link light-gray pv2">哔哩哔哩</a>
        </li>
789
        <li class="dib mr3">
790
          <a href="https://jcli.jenkins-zh.cn/" target="_blank" class="dim link light-gray pv2">Jenkins
791 792
            CLI</a>
        </li>
793
        <li class="dib mr3">
794
          <a href="https://community.jenkins-zh.cn/" target="_blank" class="dim link light-gray pv2">社区论坛</a>
795
        </li>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
796 797 798 799 800 801
      </ul>

      
    </div>

    <div>
802 803 804 805 806
      <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
deploy  
LinuxSuRen 已提交
807
        </div>
808 809 810 811 812 813
      </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
deploy  
LinuxSuRen 已提交
814 815
        </div>
      </div>
816 817 818 819 820 821 822
      <div style="color: #ffffff; display: inline-block; text-align: center; margin-right: 5px; margin-left: 5px;">微博
        <div>
          <a href="https://www.weibo.com/jenkinszh" target="_blank">
            <img src="/images/weibo-qrcode.png" with="100" height="100">
          </a>
        </div>
      </div>
823
    </div>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
824 825 826

  </div>

827
  <div class="f7 gray mb5 mb0-ns ph3 w-100"> 
828
    <p class="dib mr4"><a href="http://www.beian.miit.gov.cn/" target="_blank" rel="nofollow" class="dim link light-gray pv2"><u>晋ICP备15000444号-2</u></a></p>
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 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 881 882 883 884 885
  </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">
          博客
        </a>
    </li>
  
    <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>
  
    <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">
        <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">
        <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">
  <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>

  
</div>
<script src="/dist/app.bundle.js" type="text/javascript"></script>
</div>

886 887 888 889 890 891
  <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 已提交
892
</footer>
893
  
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
894 895 896
<link href="/dist/auto-complete.css" rel="stylesheet">
<script type="text/javascript">
    
897
        var baseurl = "https:\/\/jenkins-zh.cn";
LinuxSuRen's avatar
deploy  
LinuxSuRen 已提交
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
    
</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>
<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>
<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>


923 924 925
</body>

</html>