├── .DS_Store
├── README.md
├── basics
├── .DS_Store
├── _index.en.md
├── credential
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01-pingju.png
│ │ ├── 02-pingju.png
│ │ ├── 03-pingju.png
│ │ ├── 04-pingju.png
│ │ ├── 06-pingju-cat.png
│ │ ├── 07-pingju-create.png
│ │ ├── 08-pingju-delete.png
│ │ ├── 09-pingju-update.png
│ │ └── 10-pingju-move.png
├── installation
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01-unlockjenkins.png
│ │ ├── 02-customjenkins.png
│ │ ├── 03-createuser.png
│ │ ├── 04-updatesite.png
│ │ ├── 05-configslave.png
│ │ ├── 06-slavestatus.png
│ │ ├── 07-slavestart.png
│ │ └── 08-jenkinsconfig.png
├── introduction
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── 01-systemmanage.png
│ │ ├── 02-jobsmanager.png
│ │ ├── 03-buildinput.png
│ │ └── magic.gif
├── projectandview
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01-create.png
│ │ ├── 02-buildhistory.png
│ │ ├── 03-argsbuild.png
│ │ ├── 05-jenkinsfile.png
│ │ ├── 06-buildjobs.png
│ │ ├── 07-buildlogs.png
│ │ ├── 08-debuglogs.png
│ │ ├── 09-disablejob.png
│ │ ├── 10-typejob.png
│ │ ├── 11-movejob.png
│ │ ├── 13-views-create1.png
│ │ ├── 13-views-create2.png
│ │ ├── 13-views-create3-1.png
│ │ ├── 13-views-create3.png
│ │ ├── 13-views-create4.png
│ │ ├── 13-views-delete1.png
│ │ └── 13-views-update1.png
└── userandpermissions
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ ├── 01-configglobal.png
│ ├── 02-createuser.png
│ ├── 03-deleuser.png
│ ├── 04-updateuser.png
│ ├── 11-quanxian-type.png
│ ├── 12-manage.png
│ ├── 13-global.png
│ ├── 14-project.png
│ └── 15-assign.png
├── jenkins&docker-docs.zip
├── pipelineextension
├── .DS_Store
└── _index.en.md
├── pipelineintegrated
├── .DS_Store
├── _index.en.md
├── chapter01
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ └── 03.png
├── chapter02
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ ├── 03.png
│ │ ├── 04.png
│ │ ├── 05.png
│ │ ├── 06.png
│ │ ├── 07.png
│ │ ├── 08.png
│ │ ├── 09.png
│ │ ├── 10.png
│ │ └── 11.png
├── chapter03
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ ├── 03.png
│ │ ├── 04.png
│ │ ├── 05.png
│ │ ├── 06.png
│ │ ├── 07.png
│ │ ├── 08.png
│ │ ├── 09.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ ├── 15.png
│ │ ├── 16.png
│ │ ├── 17.png
│ │ ├── 18.png
│ │ └── 19.png
├── chapter04
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ ├── 03.png
│ │ ├── 04.png
│ │ ├── 05.png
│ │ ├── 06.png
│ │ ├── 07.png
│ │ ├── 08.png
│ │ ├── 09.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ ├── 15.png
│ │ ├── 16.png
│ │ ├── 17.png
│ │ ├── 18.png
│ │ ├── 19.png
│ │ ├── 20.png
│ │ ├── 21.png
│ │ ├── 22.png
│ │ └── 23.png
├── chapter05
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ ├── 03.png
│ │ ├── 04.png
│ │ ├── 05.png
│ │ ├── 06.png
│ │ ├── 07.png
│ │ ├── 08.png
│ │ ├── 09.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ ├── 15.png
│ │ └── 16.png
├── chapter06
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ ├── 03.png
│ │ ├── 04.png
│ │ ├── 05.png
│ │ ├── 06.png
│ │ ├── 07.png
│ │ ├── 08.png
│ │ ├── 09.png
│ │ ├── 10.png
│ │ ├── 11.png
│ │ ├── 12.png
│ │ ├── 13.png
│ │ ├── 14.png
│ │ ├── 15.png
│ │ ├── 16.png
│ │ └── 17.png
├── chapter07
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ └── 03.png
└── chapter08
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ ├── .DS_Store
│ ├── 01.png
│ ├── 02.png
│ ├── 03.png
│ ├── 04.png
│ └── 05.png
├── pipelinesyntax
├── .DS_Store
├── _index.en.md
├── chapter01
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01-subwaybeijing.jpg
│ │ ├── 02-blueocean.png
│ │ └── 03-jenkinslog.png
├── chapter02
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01-subwaybeijing.jpg
│ │ ├── 02-blueocean.png
│ │ └── 03-jenkinslog.png
├── chapter03
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ └── 03.png
├── chapter04
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ │ ├── .DS_Store
│ │ ├── 01.png
│ │ ├── 02.png
│ │ └── 03.png
└── chapter05
│ ├── .DS_Store
│ ├── _index.en.md
│ └── images
│ ├── .DS_Store
│ ├── 01.png
│ ├── 02.png
│ ├── 03.png
│ └── 04.png
└── shortcodes
├── .DS_Store
├── _index.en.md
├── _index.fr.md
├── attachments.en.files
├── BachGavotteShort.mp3
├── Carroll_AliceAuPaysDesMerveilles.pdf
├── adivorciarsetoca00cape.pdf
├── hugo.png
└── movieselectricsheep-flock-244-32500-2.mp4
├── attachments.en.md
├── attachments.fr.files
├── BachGavotteShort.mp3
├── Carroll_AliceAuPaysDesMerveilles.pdf
├── adivorciarsetoca00cape.pdf
├── hugo.png
└── movieselectricsheep-flock-244-32500-2.mp4
├── attachments.fr.md
├── button.en.md
├── button.fr.md
├── children
├── _index.en.md
├── _index.fr.md
├── children-1
│ ├── _index.en.md
│ ├── _index.fr.md
│ └── children-1-1
│ │ ├── _index.en.md
│ │ ├── _index.fr.md
│ │ └── children-1-1-1
│ │ ├── _index.en.md
│ │ ├── _index.fr.md
│ │ └── children-1-1-1-1
│ │ ├── _index.en.md
│ │ ├── _index.fr.md
│ │ └── children-1-1-1-1-1
│ │ ├── _index.en.md
│ │ └── _index.fr.md
├── children-2
│ ├── _index.en.md
│ ├── _index.fr.md
│ ├── test3.en.md
│ └── test3.fr.md
├── children-3
│ ├── _index.en.md
│ └── _index.fr.md
├── children-4
│ ├── _index.en.md
│ └── _index.fr.md
├── test.en.md
└── test.fr.md
├── expand.en.md
├── expand.fr.md
├── mermaid.en.md
├── mermaid.fr.md
├── notice.en.md
├── notice.fr.md
├── siteparam.en.md
└── siteparam.fr.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/basics/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/.DS_Store
--------------------------------------------------------------------------------
/basics/_index.en.md:
--------------------------------------------------------------------------------
1 | ### Chapter 1
2 |
3 | # Jenkins基础管理
4 |
5 |
6 | 😺您好,本模块主要讲解Jenkins的基本功能,属于基础知识自由选择跳过!
7 |
8 |
9 | | 章节名称 | 章节内容 |
10 | | ------ | ----------- |
11 | | [1-1 JENKINS简介与应用](introduction/_index.en.md) |本章我们将介绍Jenkins,让大家认识Jenkins,它能做什么?|
12 | | [1-2 JENKINS安装部署](installation/_index.en.md) | 本章我们将指导大家如何安装Jenkins,很简单,让我们一起来安装吧! |
13 | | [1-3 JENKINS用户与权限管理](userandpermissions/_index.en.md) |本章我们将指导大家在Jenkins中如何管理用户及用户权限|
14 | | [1-4 JENKINS凭据管理](credential/_index.en.md) | 本章我们将指导大家如何管理Jenkins的凭据|
15 | | [1-5 JENKINS项目与视图管理](projectandview/_index.en.md) | 本章我们将指导大家Jenkins中的项目类型,通过视图对项目进行管理 |
16 |
17 |
--------------------------------------------------------------------------------
/basics/credential/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/.DS_Store
--------------------------------------------------------------------------------
/basics/credential/_index.en.md:
--------------------------------------------------------------------------------
1 | # Jenkins凭据管理
2 |
3 |
4 | 您好,本章我们将指导大家如何管理Jenkins的凭据 😀 每个凭据会有一个唯一的ID,这个ID很重要,可以自定义也可以随机生成。(后续流水线中引用都是通过ID引用的)
5 |
6 |
7 |
8 |
9 | ### 目录
10 | + [新建凭据](#新建凭据)
11 | + [删除凭据](#删除凭据)
12 | + [更新凭据](#更新凭据)
13 | + [移动凭据](#移动凭据)
14 | + [使用凭据](#使用凭据)
15 |
16 | ---
17 | Jenkins的凭据有很多种类型,可以将一些敏感信息存储为凭据,然后在项目中引用。
18 | 凭据-> 系统-> 全局凭据
19 | 
20 |
21 | 
22 |
23 | * `Username with password`类型存储Harbor或者其他系统的用户名和密码。
24 | * `GitLab API token`类型存储Gitlab的用户API token。
25 | * `Secret text`类型可以用来存储OpenShift等系统中的token。
26 | * `Certificate`类型可以用户存储证书,例如k8s的用户证书。
27 |
28 |
29 | ### 新建凭据
30 | 选择需要创建的凭据的类型,然后输入账号和密码等信息。保存即可。
31 |
32 | 
33 |
34 | ### 删除凭据
35 | 当一些凭据已经不需要的时候,可以进行删除。
36 | 
37 |
38 | ### 更新凭据
39 | 当用户名或者密码更改后,可以选择凭据进行修改。
40 | 
41 |
42 | ### 移动凭据
43 |
44 | 目前移动凭据很少用,当存在多个阈的时候可以使用。
45 |
46 | 
47 |
48 |
49 | ### 使用凭据
50 |
51 | 我们可以在项目中增加一个凭据参数,用与项目构建中使用。
52 | 
53 |
54 | 当我们使用pipeline类型的项目的时候,我们可以通过`片段生成器`生成流水线语法
55 |
56 | * 选择要使用的凭据的类型
57 | 
58 |
59 | * 输入该凭据的账号的密码的变量名称(后续直接在流水线中使用此变量进行引用)
60 | 
61 |
62 | * 流水线代码
63 |
64 | ```
65 | withCredentials([usernamePassword(credentialsId: '24982560-17fc-4589-819b-bc5bea89da77', passwordVariable: 'password', usernameVariable: 'username')]) {
66 | // some block
67 |
68 | sh "curl -u ${username}:${password} xxxxxxxxx"
69 | }
70 | ```
71 |
72 | ---
--------------------------------------------------------------------------------
/basics/credential/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/.DS_Store
--------------------------------------------------------------------------------
/basics/credential/images/01-pingju.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/01-pingju.png
--------------------------------------------------------------------------------
/basics/credential/images/02-pingju.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/02-pingju.png
--------------------------------------------------------------------------------
/basics/credential/images/03-pingju.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/03-pingju.png
--------------------------------------------------------------------------------
/basics/credential/images/04-pingju.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/04-pingju.png
--------------------------------------------------------------------------------
/basics/credential/images/06-pingju-cat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/06-pingju-cat.png
--------------------------------------------------------------------------------
/basics/credential/images/07-pingju-create.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/07-pingju-create.png
--------------------------------------------------------------------------------
/basics/credential/images/08-pingju-delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/08-pingju-delete.png
--------------------------------------------------------------------------------
/basics/credential/images/09-pingju-update.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/09-pingju-update.png
--------------------------------------------------------------------------------
/basics/credential/images/10-pingju-move.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/credential/images/10-pingju-move.png
--------------------------------------------------------------------------------
/basics/installation/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/.DS_Store
--------------------------------------------------------------------------------
/basics/installation/_index.en.md:
--------------------------------------------------------------------------------
1 | # Jenkins安装部署
2 |
3 | 您好,本章我们将指导大家如何安装Jenkins,很简单,让我们一起来安装吧! 😀
4 |
5 |
6 | ### 目录
7 |
8 | + [先决条件](#先决条件)
9 | - [软件要求](#软件要求)
10 | - [硬件要求](#硬件要求)
11 |
12 | + [软件包下载](#软件包下载)
13 | - [war包部署](#war包部署)
14 | - [linux系统部署](#linux系统部署)
15 | - [mac系统部署](#mac系统部署)
16 | - [windows系统部署](#windows系统部署)
17 |
18 | + [安装后基本配置](#安装后基本配置)
19 | - [解锁](#解锁)
20 | - [自定义jenkins插件](#自定义jenkins插件)
21 | - [创建用户](#创建用户)
22 | - [配置更新站点](#配置更新站点)
23 | - [安装slave节点](#安装slave节点)
24 | - [jenkins配置文件](#jenkins配置文件)
25 |
26 | ---
27 |
28 | ### 先决条件
29 |
30 | #### 软件要求
31 | * Java8 无论是Java运行时环境(JRE)还是Java开发工具包(JDK)都可以。
32 |
33 | #### 硬件要求
34 | * 最低配置: 256MB可用内存,1GB可用磁盘空间(Docker推荐10GB)。
35 | * 小团队配置: 1GB+可用内存, 50GB+可用磁盘空间。
36 |
37 | ### 软件包下载
38 | * [最新war包](https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/)
39 | * [最新pkg包](http://mirrors.jenkins.io/osx/latest)
40 | * [最新exe包](http://mirrors.jenkins.io/windows/latest)
41 | * [最新rpm包](https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/)
42 |
43 | #### war包部署
44 | Jenkins的web应用程序archive(war)包是可以在任何支持Java的操作系统上运行。
45 |
46 | * 将下载的war包放到jenkins的目录中(可以自定义)。
47 | * 运行命令 `java -jar jenkins.war`启动。
48 | * 此时可以看到Jenkins的启动日志,查看是否有异常。
49 | * 通过浏览器访问`http://localhost:8080`。
50 |
51 | {{% notice info %}}
52 | 注意:可以通过 –httpPort方式指定端口, `java -jar jenkins.war -httpPort=9090。`
53 | {{% /notice %}}
54 |
55 |
56 | #### linux系统部署
57 |
58 | * 首先下载rpm软件包,安装`rpm –ivh jenkins-2.150.3-1.1.noarch.rpm`
59 | * `systemctl start jenkins` #启动服务
60 | * `systemctl enable jenkins` #开机自启
61 |
62 | #### mac系统部署
63 | 下载软件包手动安装
64 |
65 | * `brew install jenkins` 安装jenkins最新版本
66 | * `brew install jenkins-lts` 安装jenkinsLTS版本
67 |
68 |
69 | #### windows系统部署
70 | 下载软件包通过向导安装即可。
71 |
72 |
73 | ### 安装后基本配置
74 |
75 | #### 解锁
76 |
77 | 当您第一次访问Jenkins的时候,系统会要求您使用自动生成的密码对其进行解锁。解锁秘钥可以通过$JENKINS_HOME/secrets/initialAdminPassword文件获取。还可以通过在启动日志中获取。
78 |
79 | 
80 |
81 |
82 | #### 自定义jenkins插件
83 |
84 | * 解锁Jenkins之后再自定义Jenkins页面,您可以安装任何数量的插件作为初始化的一部分。
85 | * 分别是安装建议的插件和选择要安装的插件(如果不确定要安装那些的时候可以选择此选项,灵活的自定义安装)。
86 | * 插件安装多了也没关系,可以后面再jenkins插件管理页面删除哦(会很繁琐)。
87 |
88 | 
89 |
90 | #### 创建用户
91 | 在这里创建一个管理员账号,到此jenkins的初始化配置已完成。
92 | 
93 |
94 | #### 配置更新站点
95 |
96 |
97 | 当改完后,其实还是很慢 🤷♀️ 建议配置nginx做域名代理 😜
98 |
99 | 由于使用官方的站点速度相对很慢,这里采用[清华大学的jenkins更新站点](https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json)。
100 |
101 | 
102 |
103 |
104 | #### 安装slave节点
105 |
106 |
107 | 😜 注意需要开启jnlp协议才能使用java web启动,具体操作: 系统设置-> 全局安全 -> 代理配置
108 |
109 | 系统管理->节点管理
110 |
111 | 
112 |
113 | 创建完成后会出现slave节点启动的命令,下载agent.jar,然后启动服务。
114 |
115 | 
116 |
117 | 启动命令
118 |
119 | ```shell
120 | wget http://192.168.0.41/jnlpJars/agent.jar
121 | java -jar agent.jar -jnlpUrl http://192.168.0.41/computer/test1/slave-agent.jnlp -secret 807b0135fb5b071d99930166ac4fc5dd0cf355e670a66da73120dfa2e8cebc5f -workDir "/var/lib/jenkins"
122 | ```
123 |
124 | 启动成功
125 | 
126 |
127 |
128 | #### jenkins配置文件
129 | 以rpm方式部署的配置文件在/etc/sysconfig/jenkins,可以定义Jenkins启动参数和端口。
130 |
131 | 
132 |
133 |
134 |
135 | ---
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/basics/installation/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/.DS_Store
--------------------------------------------------------------------------------
/basics/installation/images/01-unlockjenkins.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/01-unlockjenkins.png
--------------------------------------------------------------------------------
/basics/installation/images/02-customjenkins.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/02-customjenkins.png
--------------------------------------------------------------------------------
/basics/installation/images/03-createuser.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/03-createuser.png
--------------------------------------------------------------------------------
/basics/installation/images/04-updatesite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/04-updatesite.png
--------------------------------------------------------------------------------
/basics/installation/images/05-configslave.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/05-configslave.png
--------------------------------------------------------------------------------
/basics/installation/images/06-slavestatus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/06-slavestatus.png
--------------------------------------------------------------------------------
/basics/installation/images/07-slavestart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/07-slavestart.png
--------------------------------------------------------------------------------
/basics/installation/images/08-jenkinsconfig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/installation/images/08-jenkinsconfig.png
--------------------------------------------------------------------------------
/basics/introduction/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/introduction/.DS_Store
--------------------------------------------------------------------------------
/basics/introduction/_index.en.md:
--------------------------------------------------------------------------------
1 | # Jenkins简介与应用
2 |
3 |
4 |
5 | 大家好,本章我们将介绍Jenkins,让大家认识Jenkins!告诉大家Jenkins是什么? 它能做什么?
6 |
7 |
8 | ### 目录
9 | + [简单介绍](#简单介绍)
10 | + [发展历史](#发展历史)
11 | + [功能特点](#功能特点)
12 | + [应用场景](#应用场景)
13 | + [web页面展示](#web页面展示)
14 |
15 | ---
16 |
17 | ### 简单介绍
18 |
19 | [Jenkins](https://jenkins.io)前身是Hudson,使用java语言开发的自动化发布工具。在中大型金融等企业中普遍使用Jenkins来作为项目发布工具。 Jenkins官方提供的插件使Jenkins更为强大。Jenkins是一个自动化服务器,目前发展超过15年,比较成熟的CI工具(也可以CD)能够实现自动化集成发布。建立好流水线后,期间无需专业运维人员介入,开发人员随时发布部署,任性!。
20 |
21 | ### 发展历史
22 | * Jenkins的前身是Hudson,采用JAVA编写的持续集成开源工具。
23 | * Hudson由Sun公司在2004年启动,第一个版本于2005年在java.net发布。
24 | * 2007年开始Hudson逐渐取代CruiseControl和其他的开源构建工具的江湖地位。
25 | * 在2008年的JavaOne大会上在开发者解决方案中获得杜克选择大奖(Duke’s Choice Award)。
26 |
27 | * 在2010年11月期间,因为Oracle对Sun的收购带来了Hudson的所有权问题。主要的项目贡献者和Oracle之间,
28 | 尽管达成了很多协议,但有个关键问题就是商标名称“Hudson”。
29 |
30 | * 甲骨文在2010年12月声明拥有该名称并申请商标的权利。因此,2011年1月11日,有人要求投票将项目名称从“Hudson”改为“Jenkins”。
31 |
32 | * 2011年1月29日,该建议得到社区投票的批准,创建了Jenkins项目。
33 |
34 | * 2011年2月1日,甲骨文表示,他们打算继续开发Hudson,并认为Jenkins只是一个分支,而不是重命名。因此,Jenkins和Hudson继续作为两个独立的项目,每个都认为对方是自己的分支。
35 | * 到2013年12月,GitHub上的Jenkins拥有567个项目成员和约1,100个公共仓库,与此相对的Hudson有32个项目成员和17个公共仓库。到现在两者的差异更多,应该说Jenkins已经全面超越了Hudson。此外,大家可能是出于讨厌Oracle的情绪,作为Java开发者天然地应该支持和使用Jenkins。
36 |
37 |
38 | ### 功能特点
39 | * 开源免费
40 | * 多平台支持(windows/linux/macos)
41 | * 主从分布式架构
42 | * 提供web可视化配置管理页面
43 | * 安装配置简单
44 | * 插件资源丰富
45 |
46 |
47 | ### 应用场景
48 | * 集成svn/git客户端实现源代码下载检出
49 | * 集成maven/ant/gradle/npm等构建工具实现源码编译打包单元测试
50 | * 集成sonarqube对源代码进行质量检查(坏味道、复杂度、新增bug等)
51 | * 集成SaltStack/Ansible实现自动化部署发布
52 | * 集成Jmeter/Soar/Kubernetes/.....
53 | * 可以自定义插件或者脚本通过jenkins传参运行
54 | * 可以说Jenkins比较灵活插件资源丰富,日常运维工作都可以自动化。
55 |
56 | ### web页面展示
57 |
58 | * 管理页面: 系统管理页面包含系统管理、全局安全管理、全局工具配置、节点管理、授权管理、插件管理、系统备份管理、日志监控管理
59 |
60 | 
61 |
62 | * 项目管理页面: 项目、项目状态、项目视图、构建队列等信息
63 |
64 | 
65 |
66 | * 构建输出页面: 用于查看项目的构建详情,能够看到项目的构建过程及详细日志。
67 |
68 | 
69 |
70 | ---
71 |
--------------------------------------------------------------------------------
/basics/introduction/images/01-systemmanage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/introduction/images/01-systemmanage.png
--------------------------------------------------------------------------------
/basics/introduction/images/02-jobsmanager.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/introduction/images/02-jobsmanager.png
--------------------------------------------------------------------------------
/basics/introduction/images/03-buildinput.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/introduction/images/03-buildinput.png
--------------------------------------------------------------------------------
/basics/introduction/images/magic.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/introduction/images/magic.gif
--------------------------------------------------------------------------------
/basics/projectandview/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/.DS_Store
--------------------------------------------------------------------------------
/basics/projectandview/_index.en.md:
--------------------------------------------------------------------------------
1 | # Jenkins项目与视图管理
2 |
3 | 您好,本章我们将指导大家Jenkins中的项目类型,通过视图对项目进行管理 😀 创建一个项目很简单,如何管理大规模下的项目呢? -建立合适的命名规范。
4 |
5 |
6 |
7 | ### 目录
8 | + [项目管理](#项目管理)
9 | - [新建项目](#新建项目)
10 | - [删除禁用项目](#删除禁用项目)
11 | - [项目分类](#项目分类)
12 |
13 | + [视图管理](#视图管理)
14 | - [创建视图](#创建视图)
15 | - [删除视图](#删除视图)
16 | - [更新视图](#更新视图)
17 |
18 | ---
19 |
20 |
21 | ### 项目管理
22 |
23 | 管理项目的前提是,具有合理的命名规范。 命名规范: 业务名称-应用名称-应用类型_环境类型: cxy-wlck-ui_TEST, 有命名规范后会更加方便管理项目。
24 |
25 |
26 | #### 新建项目
27 |
28 | 新建一个项目,项目的类型有很多,例如自由风格的项目、maven类型项目等。这里我们主要用的是流水线pipeline类型的项目。
29 |
30 | 
31 |
32 | 设置构建历史:构建历史要有合理的策略,过多历史数据会导致jenkins磁盘空间增大。例如:保留30天内的近20次构建记录。
33 |
34 | 
35 |
36 | 选择参数化构建: 参数化构建就是将项目的信息变成编程语言中的变量,便于后期流水线运行时引用。
37 |
38 | 
39 |
40 | 设置Jenkinsfile:
41 | Jenkinsfile如同dockerfile,在docker中使用dockerfile创建出一个镜像,在jenkins中使用jenkinsfile定义项目流水线的运行步骤和运行相关配置。Jenkinsfile可以直接写在项目中,也可以通过scm版本控制系统进行管理。选择后种方式便于回退,更加友好。
42 |
43 | 
44 |
45 | 构建项目: 很简单,直接点击构建就好了。当然触发构建的方式后很多,见后续扩展内容。
46 | 
47 |
48 | 查看构建日志: 构建日志是一条流水线项目的运行步骤信息,例如构建的错误信息等。便于排错。
49 | 
50 |
51 | 调试Pipeline:当流水线出问题的时候,可以不直接修改源文件,而是通过流水线的回放功能进行编辑调试运行。很有用的功能,便于调试。
52 |
53 |
54 |
55 | #### 删除禁用项目
56 | 当项目不需要的时候可以进行先禁用再删除。
57 | 
58 |
59 | #### 项目分类
60 | 当项目很多时候可以按照项目或者业务建立文件夹,将同业务的项目移动到文件夹中。
61 | 
62 |
63 | 移动项目
64 | 
65 |
66 | ---
67 |
68 | ### 视图管理
69 | 默认Jenkins会自动创建一个all视图,里面存放所有的项目。
70 |
71 |
72 | #### 创建视图
73 | 点击加号新建视图
74 | 
75 |
76 | 填写视图的名称,选择列表视图
77 | 
78 |
79 | 选择视图包含的项目。这里使用正则表达式的方式,当然也可以直接手动选择。
80 | 
81 |
82 | 创建完成
83 | 
84 |
85 | #### 删除视图
86 |
87 | 
88 |
89 | #### 更新视图
90 | 
91 |
92 | ---
93 |
94 |
--------------------------------------------------------------------------------
/basics/projectandview/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/.DS_Store
--------------------------------------------------------------------------------
/basics/projectandview/images/01-create.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/01-create.png
--------------------------------------------------------------------------------
/basics/projectandview/images/02-buildhistory.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/02-buildhistory.png
--------------------------------------------------------------------------------
/basics/projectandview/images/03-argsbuild.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/03-argsbuild.png
--------------------------------------------------------------------------------
/basics/projectandview/images/05-jenkinsfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/05-jenkinsfile.png
--------------------------------------------------------------------------------
/basics/projectandview/images/06-buildjobs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/06-buildjobs.png
--------------------------------------------------------------------------------
/basics/projectandview/images/07-buildlogs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/07-buildlogs.png
--------------------------------------------------------------------------------
/basics/projectandview/images/08-debuglogs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/08-debuglogs.png
--------------------------------------------------------------------------------
/basics/projectandview/images/09-disablejob.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/09-disablejob.png
--------------------------------------------------------------------------------
/basics/projectandview/images/10-typejob.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/10-typejob.png
--------------------------------------------------------------------------------
/basics/projectandview/images/11-movejob.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/11-movejob.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-create1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-create1.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-create2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-create2.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-create3-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-create3-1.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-create3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-create3.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-create4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-create4.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-delete1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-delete1.png
--------------------------------------------------------------------------------
/basics/projectandview/images/13-views-update1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/projectandview/images/13-views-update1.png
--------------------------------------------------------------------------------
/basics/userandpermissions/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/.DS_Store
--------------------------------------------------------------------------------
/basics/userandpermissions/_index.en.md:
--------------------------------------------------------------------------------
1 | # Jenkins用户与权限管理
2 |
3 |
4 | 您好,本章我们将指导大家在Jenkins中如何管理用户及用户权限 😀
5 |
6 |
7 |
8 | ### 目录
9 | + [用户管理](#用户管理)
10 | - [查看用户](#查看用户)
11 | - [新建用户](#新建用户)
12 | - [删除用户](#删除用户)
13 | - [更新用户](#更新用户)
14 |
15 | + [权限管理](#权限管理)
16 | - [管理权限](#管理权限)
17 | - [全局权限](#全局权限)
18 | - [项目权限](#项目权限)
19 | - [权限授权](#权限授权)
20 |
21 | ---
22 |
23 |
24 | Jenkins默认使用的是自带的数据库管理用户,支持同步LDAP、Github等认证集成。关于用户与权限管理是Jenkins比较弱的一点,当大规模授权的时候建议使用API接口授权,否则当你打开web页面授权时,会很乱加载缓慢,最终导致保存失败权限丢失。
25 |
26 | ### 用户管理
27 | * 配置用户接入入口: 系统管理->全局安全配置。
28 | * 默认使用的是Jenkins数据库存储。
29 | * 可以选择集成LDAP服务或者是GItlab服务(需要安装插件后才能使用,后面会讲解)。
30 |
31 | 
32 |
33 |
34 | #### 查看用户
35 | 以使用Jenkins专有数据库为例,用户管理入口: 系统管理-> 管理用户
36 |
37 |
38 | #### 新建用户
39 | 
40 |
41 | #### 删除用户
42 | 
43 |
44 |
45 | #### 更新用户
46 | 
47 |
48 | ---
49 |
50 | ### 权限管理
51 |
52 | > 注意安装插件: 权限默认使用 Role-Based Strategy,其他方式如图所示。
53 |
54 | 
55 |
56 | #### 管理权限
57 |
58 | - 系统设置->Manage and Assign Roles->Manage Roles
59 | - Global roles:添加用户和用户组,分配某个用户属于哪个用户组。
60 | - Project roles:添加某个工程或某一组工程的用户或用户组
61 | - Slave roles:添加某个节点或某一组节点的用户或用户组
62 |
63 | 
64 |
65 |
66 | #### 全局权限
67 |
68 | 
69 |
70 | #### 项目权限
71 |
72 | 
73 |
74 |
75 | #### 权限授权
76 | 
77 |
--------------------------------------------------------------------------------
/basics/userandpermissions/images/01-configglobal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/01-configglobal.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/02-createuser.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/02-createuser.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/03-deleuser.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/03-deleuser.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/04-updateuser.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/04-updateuser.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/11-quanxian-type.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/11-quanxian-type.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/12-manage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/12-manage.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/13-global.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/13-global.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/14-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/14-project.png
--------------------------------------------------------------------------------
/basics/userandpermissions/images/15-assign.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/basics/userandpermissions/images/15-assign.png
--------------------------------------------------------------------------------
/jenkins&docker-docs.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/jenkins&docker-docs.zip
--------------------------------------------------------------------------------
/pipelineextension/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineextension/.DS_Store
--------------------------------------------------------------------------------
/pipelineextension/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 流水线扩展篇[待更新]
3 | weight: 25
4 | pre: "5. "
5 | chapter: true
6 | ---
7 |
8 | ### Chapter 5
9 |
10 | # 流水线扩展篇
11 |
12 |
--------------------------------------------------------------------------------
/pipelineintegrated/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 流水线集成篇
3 | weight: 15
4 | pre: "3. "
5 | chapter: true
6 | ---
7 |
8 | ### Chapter 3
9 |
10 | # 流水线集成篇
11 |
12 | {{% notice tip %}}
13 | 😺您好,本模块主要讲解Jenkins如何与其他工具链系统集成, 注意不会讲解太多关于外围系统的知识,如需了解更多可以查阅外围系统的官方文档!
14 | {{% /notice %}}
15 |
16 |
17 | | 章节名称 | 章节内容 |
18 | | ------ | ----------- |
19 | | [3-1 构建发布工具集成](chapter01/_index.en.md) |本章我们将学习Jenkins与常用的构建发布工具集成|
20 | | [3-2 用户认证系统集成](chapter02/_index.en.md) | 本章我们将为大家讲述用用户认证系统集成|
21 | | [3-3 版本控制系统集成](chapter03/_index.en.md) |本章我们将学习Jenkins与版本控制系统集成|
22 | | [3-4 质量管理平台集成](chapter04/_index.en.md) | 本章主要讲述Jenkins与质量管理平台集成|
23 | | [3-5 制品仓库集成](chapter05/_index.en.md) | 本章我们主要讲述Jenkins与制品库集成 |
24 | | [3-6 需求管理平台集成](chapter06/_index.en.md) | 本章我们主要讲述Jenkins与需求管理平台集成 |
25 | | [3-7 容器PaaS平台集成](chapter07/_index.en.md) | 本章我们主要讲述Jenkins与与容器PaaS平台集成 |
26 | | [3-8 自动化接口测试](chapter08/_index.en.md) | 本章我们主要讲述Jenkins完成自动化接口测试 |
27 |
28 |
29 | ## FAQ
30 |
31 | ### Q1什么是集成?
32 | 所谓的集成是通过Jenkins与外部系统或工具之间的调用,而不是Jenkins本身具备其他外围系统的功能。例如:与maven集成,我们不能去认为Jenkins自身已经具有maven打包构建的功能,而是jenkins调用maven去进行打包构建! 所以打包出现的问题未必一定是Jenkins的问题,80%因为代码无法完成编译等步骤导致的。
--------------------------------------------------------------------------------
/pipelineintegrated/chapter01/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter01/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter01/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-1 构建发布工具集成
3 | weight: 15
4 | ---
5 |
6 | {{% notice tip %}}
7 | 您好,本章主要讲解与构建工具和发布部署工具的集成!例如: Maven、Ant、Gradle、Npm、Saltstack、Ansible 😀
8 | {{% /notice %}}
9 |
10 | 
11 |
12 | ### 目录
13 |
14 | + [构建工具安装](#构建工具安装)
15 | - [软件包下载](#软件包下载)
16 | - [配置环境](#配置环境)
17 | + [构建工具集成](#构建工具集成)
18 | - [通过Jenkins配置](#通过Jenkins配置)
19 | - [通过Jenkinsfile配置](#通过Jenkinsfile配置)
20 | + [发布工具安装](#发布工具安装)
21 | - [安装saltstck](#安装saltstck)
22 | - [安装ansible](#安装ansible)
23 | + [发布工具集成](#发布工具集成)
24 |
25 | ---
26 |
27 | ### 构建工具安装
28 |
29 | {{% notice info %}}
30 | 构建工具是安装到`master`还是`node`节点呢? 很显然安装在master节点并不友好,一般我们不会让master节点执行构建任务的,我们都是使用node节点完成构建任务。所以我们要部署在node节点中哦。(当然我只是做实验所以部署到了master节点,生产环境不要这么做哦!)
31 | {{% /notice %}}
32 |
33 | 这些构建工具的安装很简单的,只需要在每个构建工具的官网找到软件包,然后下载到本地解压并配置环境变量就好了。接下来我们实践一下!
34 |
35 | #### 软件包下载
36 | * [maven软件包下载](http://maven.apache.org/download.cgi)
37 | * [gradle软件包下载](https://downloads.gradle.org/distributions/gradle-5.3-bin.zip)
38 | * [ant软件包下载](https://ant.apache.org/bindownload.cgi)
39 | * [node软件包下载](https://nodejs.org/en/download/)
40 |
41 | #### 配置环境
42 |
43 | ```bash
44 | #解压
45 | tar zxf apache-maven-xxxx.tar.gz -C /usr/local
46 | tar zxf gradle-xxxx.tar.gz -C /usr/local
47 | tar zxf node-xxxxx.tar.gz -C /usr/local
48 | tar zxf apache-ant-xxxx.tar.gz -C /usr/local
49 |
50 | #添加环境变量
51 | vim /etc/profile
52 | export MAVEN_HOME=/usr/local/apache-maven-3.6.0
53 | export ANT_HOME=/usr/local/apache-ant-1.10.5
54 | export GRADLE_HOME=/usr/local/gradle-5.3
55 | export NODE_HOME=/usr/local/node-v10.15.3-linux-x64
56 | export JAVA_HOME=/usr/local/jdk1.8.0_201
57 | export PATH=$PATH:$MAVEN_HOME/bin:$ANT_HOME/bin:$GRADLE_HOME/bin:$NODE_HOME/bin
58 | export PATH=$PATH:$JAVA_HOME/bin
59 |
60 | # 生效全局环境变量
61 | source /etc/profile
62 | ```
63 |
64 |
65 | ### 构建工具集成
66 | 在这里需要强调一下,Jenkins调用这些工具的方式是通过环境变量调用。有两种方式 一种是在Jenkins系统配置中添加构建工具的环境变量,一种是直接在Jenkinsfile中定义。实现的效果没有区别,而后者更加灵活对于配置Jenkins无状态化有好处。
67 |
68 |
69 | #### 通过Jenkins配置
70 |
71 | {{% notice info %}}
72 | 我们打开系统管理-> `全局工具配置`页面,这里就是配置我们在运行流水线过程中使用的构建工具的地方。如果没有找到`maven`需要安装插件`Maven Integration`才能有哦。
73 | {{% /notice %}}
74 |
75 | 在这里我们通过变量名和变量值的方式定义好构建工具,变量名称不能冲突,可以大小写。关于变量的值保守点可以定义成MAVE_HOME`/usr/local/apache-maven-3.6.0/`,也可以写成绝对路径`/usr/local/apache-maven-3.6.0/bin/mvn`。 定义好工具之后我们如何在Jenkinsfile中使用工具呢?
76 |
77 | 
78 |
79 |
80 | 在Jenkinsfile中使用: 如上图所示,我定义的maven变量名称为`M3`,接下来在Jenkinsfile中使用`tool`获取变量值。如下:
81 |
82 | ```
83 | stage("mavenBuild"){
84 | steps{
85 | script{
86 | def mvnHome = tool 'M3'
87 | sh "${mvnHome}/bin/mvn clean package "
88 | }
89 | }
90 | }
91 | ```
92 |
93 |
94 |
95 |
96 | #### 通过Jenkinsfile配置
97 | 在Jenkinsfile中定义其实跟我们在上面的系统中定义是一样的,我们只需要将变量名和值直接定义在文件中。然后直接调用。
98 |
99 | ```
100 | stage("mavenBuild"){
101 | steps{
102 | script{
103 | def mvnHome = '/usr/local/apache-maven-3.6.0'
104 | sh "${mvnHome}/bin/mvn clean package "
105 | }
106 | }
107 | }
108 | ```
109 |
110 | 现在你是否清楚了关于构建工具的集成呢?类似的例如您当前用的构建工具不在我的举例范围内,相信你通过这篇文章也知道了如何来进行集成了。对的没错:在系统中安装好构建工具,在jenkinsfile中定义好环境变量即可。特殊工具特殊对待哦!
111 |
112 |
113 |
114 |
115 | ### 发布工具安装
116 | 关于发布工具我们常用的是`saltstack`和`ansible`这个两个工具,这里简单说下如何集成。
117 |
118 |
119 | #### 安装saltstck
120 | saltstack也是C/S架构,需要在应用服务器安装salt-minion客户端。
121 |
122 | yum源:https://mirrors.tuna.tsinghua.edu.cn/saltstack/#rhel
123 |
124 | ```bash
125 | #install
126 | yum –y install salt-master salt-minion
127 |
128 | #start
129 | service salt-master start
130 | service salt-minion start
131 |
132 | #enable
133 | chkconfig salt-master on
134 | chkconfig salt-minion on
135 | ```
136 | ---
137 |
138 |
139 | #### 安装ansible
140 | ansible不需要安装客户端,是通过SSH协议通信的。使用`/etc/ansible/hosts`文件控制主机。
141 |
142 | ```
143 | yum install epel-release ansbile
144 | service ansible start
145 | ```
146 |
147 |
148 | ### 发布工具集成
149 |
150 | ```
151 | stage("SlatDeploy"){
152 | steps{
153 | script{
154 |
155 | //saltstack
156 | sh " salt ${host} test.ping "
157 |
158 | //ansible
159 | sh " ansible -m ping ${host} "
160 | }
161 | }
162 | }
163 | ```
164 |
165 | 关于发布工具暂且就这些了,有关发布工具的详细内容还需要各位自行在官方阅读哦。saltstack有API服务可以在jenkinsfile中封装HTTP API。
166 |
167 | ---
168 |
169 |
--------------------------------------------------------------------------------
/pipelineintegrated/chapter01/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter01/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter01/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter01/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter01/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter01/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter01/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter01/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-2 用户认证系统集成
3 | weight: 20
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本章主要讲解与jenkins与用户认证系统集成 例如:LDAP Gitlab GitHub 。我们做实验的过程中建议先开启匿名模式,防止配置错误导致无法直接登录。 😀
9 | {{% /notice %}}
10 |
11 |
12 |
13 | ### 目录
14 |
15 | + [ldap系统集成](#ldap系统集成)
16 | + [gitlab单点登录](#gitlab单点登录)
17 | - [gitlab配置](#gitlab配置)
18 | - [jenkins配置](#jenkins配置)
19 | + [github单点登录](#github单点登录)
20 | - [github配置](#github配置)
21 | - [配置jenkins](#配置jenkins)
22 |
23 | ---
24 |
25 | Jenkins默认使用自带数据库模式存储用户,在企业中一般都会有统一的认证中心,例如 LDAP、ActiveDirectory中管理用户。可以配置Jenkins集成实现统一用户管理。
26 |
27 | ### ldap系统集成
28 |
29 | LDAP系统是用于用户管理,在配置集成的时候我们只需要以下信息:
30 |
31 | * 服务器地址: ldap://192.168.1.200
32 | * 服务器端口: 389
33 | * 组织OU: ou=jenkins,dc=devops,dc=com
34 | * 管理员账号和密码: cn=admin,dc=devops,dc=com
35 |
36 | 首先,我需要在Jenkins系统中安装`LDAP`插件,然后进入 系统管理 -> `全局安全配置`页面中。
37 |
38 | 
39 |
40 | 填写好信息之后,我们可以点击测试按钮进行测试。会模拟用户登录,成功后再保存配置即可。
41 |
42 | 
43 |
44 |
45 |
46 | ### gitlab单点登录
47 | 一般我们会配置Gitlab系统与LDAP系统做用户认证集成,开发人员登录gitlab系统的频率还是很多的,今天我们的配置效果是:当用户已经登录了gitlab,再次打开Jenkins会自动登入。
48 |
49 |
50 | #### gitlab配置
51 | 首先,我们需要在Gitlab中添加一个应用。系统设置 -> 应用管理
52 |
53 | 填写Jenkins回调地址`http://jenkinsserver:8080/securityRealm/finishLogin`,勾选权限默认具有`read_user`权限即可。
54 |
55 | 
56 |
57 | 保存配置,会提示以下信息,这些信息需要填写到Jenkins中。`ApplicationId` `secret`
58 | 
59 |
60 | #### jenkins配置
61 |
62 | 我们需要在Jenkins系统中安装插件`Gitlab Authentication`, 然后导航到`全局安全配置`。
63 | 填写Gitlab系统地址和上面在Gitlab创建的应用的`ApplicationId` `secret`。
64 | 
65 |
66 |
67 | {{% notice info %}}
68 | 注意:当Jenkins前面有代理的时候可能会出现跳转错误的问题。这时候需要看下提示错误的redirect URL地址,检查下图配置。 如果下图配置没有问题,请检查代理的配置问题。另外要注意是`http`模式哦
69 | {{% /notice %}}
70 | 
71 |
72 |
73 | ### github单点登录
74 | 如果你用过GitLab,你会发现与GitHub很类似。这里我们要配置的GitHub集成与GitLab配置很类似。
75 |
76 |
77 | #### github配置
78 | 首先登录GitHub, settings -> Developer Settings -> Oauth Apps。
79 | 
80 |
81 | 新建应用:填写Jenkins回调地址`http://jenkinsserver:8080/securityRealm/finishLogin`。
82 | 
83 |
84 | 保存,获取应用ID和secret
85 | 
86 |
87 |
88 | #### 配置jenkins
89 | 我们需要在Jenkins系统中安装插件`Github Authentication`, 然后导航到`全局安全配置`。
90 | 填写Gitlab系统地址和上面在Gitlab创建的应用的`ApplicationId` `secret`。
91 |
92 | 
93 |
94 |
95 | 效果:
96 | 
97 |
98 | ---
99 |
100 |
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/04.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/05.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/06.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/07.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/08.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/09.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/10.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter02/images/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter02/images/11.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-3 版本控制系统集成
3 | weight: 25
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本章主要我们主要学习与版本控制系统Gitlab的集成,例如:配置提交流水线和合并流水线。
9 | {{% /notice %}}
10 |
11 |
12 |
13 | ### 目录
14 |
15 | + [提交流水线](#提交流水线)
16 | - [配置jenkins](#配置jenkins)
17 | - [配置gitlab](#配置gitlab)
18 | + [提交流水线优化](#提交流水线优化)
19 | - [分支名称自动替换](#分支名称自动替换)
20 | - [增加构建描述信息](#增加构建描述信息)
21 | - [变更commit状态](#变更commit状态)
22 | - [构建失败邮件通知](#构建失败邮件通知)
23 | - [过滤特殊push请求](#过滤特殊push请求)
24 | + [合并流水线](#合并流水线)
25 |
26 | ---
27 |
28 | ### 提交流水线
29 | 当Gitlab中触发push操作,则触发相对应的Jenkins流水线构建。实现快速反馈与验证。
30 |
31 | * 方式1: 使用Gitlab CI,当有push请求,在CI脚本中远程触发Jenkins项目构建。
32 | - 需要准备Gitlab runner
33 | - 编写触发Jenkins脚本
34 | * 方式2: 使用Gitlab WebHook,当有push请求,直接触发jenkins项目构建。【采用】
35 | - 需要配置Gitlab webHook
36 | - 需要配置Jenkins项目Hook
37 |
38 | #### 配置jenkins
39 |
40 | 首先我们准备一个能够构建成功的流水线项目(暂且不设置复杂的步骤,helloworld即可)
41 | 
42 |
43 | 编辑项目配置: 我们要使用`Generic Webhook Trigger`触发器,需要安装插件。这触发器非常灵活,推荐使用。
44 |
45 | 
46 |
47 | 开启`Generic Webhook Trigger`触发器,添加一个请求参数runOpts `Request parameters` 。我们定义这个参数是为了对构建做个标识。辨别手动触发构建与提交构建。配置一个`token`默认我使用的是项目的名称,必须唯一,否则在配置了相同的token的项目都会被触发。`Print post content`用于展示请求日志,`Print contributed variables`展示我们在post中获取的变量内容。
48 |
49 | 
50 |
51 | 配置完成后: 我们生成一个触发URL
52 |
53 | 
54 | `http://JENKINS_URL/generic-webhook-trigger/invoke?token=demo-maven-service_PUSH&runOpts=GitlabCI`
55 |
56 |
57 | #### 配置gitlab
58 | 我们找到要配置提交触发构建的项目,设置->集成,勾选`Push Events`
59 | 
60 |
61 | {{% notice info %}}
62 | 配置完成,这时候我们进行提交代码,会发现已经能够正常触发项目构建了。如果出现了问题,我们重点检查jenkins的项目触发URL和网络权限问题。
63 | {{% /notice %}}
64 |
65 |
66 | ### 提交流水线优化
67 |
68 | #### 分支名称自动替换
69 | 当我们在任意分支提交的时候,Jenkins需要获取我们提交的分支进行构建。而不是固定的分支。
70 |
71 | 增加获取hook参数 分支名称变量 `Post content parameters`. `$`指的是在Gitlab系统中`push`操作触发后发送给Jenkins的数据。(这个数据包含谁提交的、提交的分支、提交的id等信息)。而`$.ref`是解析这个json格式的数据,获取其中的`ref`也就是提交的分支名称。
72 | 
73 |
74 | 查看下面这段jenkinsfile,你会发现`branch`变量就是上面我们在触发器中配置的,它的原始内容是`refs/heads/master`,因为我们在下载代码的时候不需要前面`refs/heads/`内容,所以去掉了。此时可以重复在不通的分支提交代码,当在构建日志中出现了不通的分支名称,则成功了。
75 |
76 | ```
77 | branchName = branch - "refs/heads/"
78 |
79 | //pipeline
80 | pipeline{
81 | agent { node { label "build"}}
82 | stages{
83 |
84 | stage("CheckOut"){
85 | steps{
86 | script{
87 | println("${branchName}")
88 | }
89 | }
90 | }
91 | }
92 | }
93 | ```
94 |
95 | #### 增加构建描述信息
96 | 别忘了我们在前面构建触发器中配置了`runOpts`参数,这个参数我们用于区分不通的构建触发方式(手动、提交触发)。 这时候我们可以结合`currendBuild.description`配置。
97 |
98 | 为了更加明显我们可以在触发器中再添加一个参数,用户获取提交的用户。
99 |
100 | 
101 |
102 | 然后我们来完善一下上面的Jenkinsfile,如下:
103 |
104 | ```
105 | branchName = branch - "refs/heads/"
106 | currentBuild.description = "Trigger by ${userName} ${branch}"
107 |
108 | //pipeline
109 | pipeline{
110 | agent { node { label "build"}}
111 | stages{
112 |
113 | stage("CheckOut"){
114 | steps{
115 | script{
116 | println("${branchName}")
117 | }
118 | }
119 | }
120 | }
121 | }
122 | ```
123 |
124 | 改好了之后,我们可以进行调试了。当你在项目的构建记录中看到下图信息,表名成功了。
125 |
126 | 
127 |
128 |
129 | #### 变更commit状态
130 | 其实,Gitlab自身的GitlabCI很好用,能够根据流水线的状态设置当前提交的状态。而我们使用Jenkins也是可以完成这样的配置。这个需要我们去研究Gitlab的API。先看下效果吧!
131 | 
132 |
133 | 开始配置: 需要研究[Gitlab的Pipeline接口文档](https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit) 关于gitlab中pipeline的状态有:[pending, running, success, failed, canceled] 。 接口地址为`projects/${projectId}/statuses/${commitSha}?state=state`。
134 |
135 | 搞清楚了上面这些,我们在共享库中进行封装就很简单了。 开始吧!可以看到我们还需要一些信息例如:`projectId`gitlab项目的ID,`commitSha`提交的id。我们该如何获取呢? 对的,没错我们根据上面的操作一样获取。 首先在触发器添加两个参数`projectId`,`commitSha`,分别对应项目Id和提交Id。 `$.project.id`,`$.checkout_sha`
136 | 
137 |
138 | ok!很好,我们接下来在共享库创建一个文件`src/org/devops/gitlab.groovy`,这个文件用与后续的Gitlab操作。然后我们在jenkins中添加一个凭据用户存储Gitlab的token,这里我定义的凭据名称是`gitlab-token` 。我们首先使用`httpRequest`封装请求Gitlab的API地址,然后使用`withCredentials`获取Jenkins中的凭据`gitlab-token`赋值给变量`gitlabToken`用于认证使用。
139 |
140 | ```
141 | package org.devops
142 |
143 | //封装HTTP请求
144 | def HttpReq(reqType,reqUrl,reqBody){
145 | def gitServer = "http://192.168.1.200:30088/api/v4"
146 | withCredentials([string(credentialsId: 'gitlab-token', variable: 'gitlabToken')]) {
147 | result = httpRequest customHeaders: [[maskValue: true, name: 'PRIVATE-TOKEN', value: "${gitlabToken}"]],
148 | httpMode: reqType,
149 | contentType: "APPLICATION_JSON",
150 | consoleLogResponseBody: true,
151 | ignoreSslErrors: true,
152 | requestBody: reqBody,
153 | url: "${gitServer}/${reqUrl}"
154 | //quiet: true
155 | }
156 | return result
157 | }
158 | ```
159 | {{% notice info %}}
160 | 如果上面的内容你有点看不懂了,嘿嘿,先放放。你可以去了解下关于HTTP请求相关基础知识了。
161 | {{% /notice %}}
162 |
163 |
164 | 我们开始添加变更提交状态的方法(记住我们现在还在gitlab.groovy文件中哦),我们定义一个`ChangeCommitStatus()`方法,具有三个参数分别为项目ID、提交ID、提交状态 `projectId`,`commitSha`,`status`。然后使用我们上面封装好的方法发送`POST`请求。
165 |
166 | ```
167 | //更改提交状态
168 | def ChangeCommitStatus(projectId,commitSha,status){
169 | commitApi = "projects/${projectId}/statuses/${commitSha}?state=${status}"
170 | response = HttpReq('POST',commitApi,'')
171 | println(response)
172 | return response
173 | }
174 | ```
175 |
176 | 到此我们在共享库的配置就完成了,接下来在Jenkinsfile中引用并进行调试。首先我们先加载了共享库`jenkinslibrary` 然后引用了gitlab.groovy。当流水线开始运行的时候我们将当前这次提交的状态为`running`运行中状态,当流水线构建成功我们会把状态变为`success`,当流水线失败了或者被取消了我们会将状态变为`failed`,`canceled`。
177 |
178 | ```
179 | #!groovy
180 |
181 | @Library('jenkinslibrary@master') _
182 |
183 | //func from shareibrary
184 | def gitlab = new org.devops.gitlab()
185 |
186 | //branch
187 | branchName = branch - "refs/heads/"
188 | currentBuild.description = "Trigger by ${userName} ${branch}"
189 | gitlab.ChangeCommitStatus(projectId,commitSha,"running")
190 |
191 |
192 | //pipeline
193 | pipeline{
194 | agent { node { label "build"}}
195 | stages{
196 |
197 | stage("CheckOut"){
198 | steps{
199 | script{
200 | println("${branchName}")
201 | }
202 | }
203 | }
204 | }
205 |
206 | post {
207 | always{
208 | script{
209 | println("always")
210 | }
211 | }
212 |
213 | success{
214 | script{
215 | println("success")
216 | gitlab.ChangeCommitStatus(projectId,commitSha,"success")
217 |
218 | }
219 |
220 | }
221 | failure{
222 | script{
223 | println("failure")
224 | gitlab.ChangeCommitStatus(projectId,commitSha,"failed")
225 |
226 | }
227 | }
228 |
229 | aborted{
230 | script{
231 | println("aborted")
232 | gitlab.ChangeCommitStatus(projectId,commitSha,"canceled")
233 | }
234 |
235 | }
236 |
237 | }
238 |
239 | }
240 | ```
241 |
242 | 如果调试没有问题,那么此时你可以登录gitlab系统当前项目的分支的提交的状态了!但是你是否觉得还差点什么? 如果开发人员提交了,然后流水线自动执行了,最后失败了怎么办? 要求开发人员放下工作实时去看?我觉得发送一个通知会更好一些! 例如邮件通知。好吧,开始配置!
243 |
244 | #### 构建失败邮件通知
245 | 首先要为每个开发人员分配一个邮箱,并且要在Gitlab中填写好。登录个人用户进行配置哦!没错,在这里配置邮箱的意义就是方便后面我们在jenkins中过滤获取。当然如果公司邮箱具有特征:用户名@xxx.com。就不用配置了因为前面已经获取的用户名。当然很多时候不是这样的,所以我们有必要把这个配置好。
246 |
247 | 
248 |
249 | 配置好邮箱之后,我们需要在Jenkins中配置邮件通知和项目配置。我们在项目中触发器添加一个参数`userEmail`。
250 |
251 | 
252 |
253 | Jenkins需要配置邮件通知,安装插件`Email Extension`,然后进入系统管理-> `系统设置` ->`Extended E-email Notification`。这里我使用的是QQ邮箱,填写SMTP服务器地址`smtp.qq.com` 和端口 `465`注意要开启SSL,密码为授权码。
254 |
255 | 
256 |
257 | 邮件通知的功能很重要,我们要为每条流水线都加上这个步骤,我们在共享库中封装一个`toemail.groovy`。 新建文件`src/org/devops/toemail.groovy`。在这个文件中,我们写了一段HTML代码,主要展示Jenkins的构建信息。
258 |
259 | ```
260 | package org.devops
261 |
262 | //定义邮件内容
263 | def Email(status,emailUser){
264 | emailext body: """
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 | 构建信息
276 | |
277 |
278 |
279 |
280 |
287 | |
288 |
289 |
290 |
291 |
292 | """,
293 | subject: "Jenkins-${JOB_NAME}项目构建信息 ",
294 | to: emailUser
295 | }
296 | ```
297 |
298 | 在流水线中引用
299 |
300 | ```
301 | #!groovy
302 |
303 | @Library('jenkinslibrary@master') _
304 |
305 | //func from shareibrary
306 | def gitlab = new org.devops.gitlab()
307 | def toemail = new org.devops.toemail()
308 |
309 | //branch
310 | branchName = branch - "refs/heads/"
311 | currentBuild.description = "Trigger by ${userName} ${branch}"
312 | gitlab.ChangeCommitStatus(projectId,commitSha,"running")
313 |
314 |
315 | //pipeline
316 | pipeline{
317 | agent { node { label "build"}}
318 | stages{
319 |
320 | stage("CheckOut"){
321 | steps{
322 | script{
323 | println("${branchName}")
324 | }
325 | }
326 | }
327 | }
328 |
329 | post {
330 | always{
331 | script{
332 | println("always")
333 | }
334 | }
335 |
336 | success{
337 | script{
338 | println("success")
339 | gitlab.ChangeCommitStatus(projectId,commitSha,"success")
340 | toemail.Email("流水线成功",userEmail)
341 | }
342 |
343 | }
344 | failure{
345 | script{
346 | println("failure")
347 | gitlab.ChangeCommitStatus(projectId,commitSha,"failed")
348 | toemail.Email("流水线失败了!",userEmail)
349 | }
350 | }
351 |
352 | aborted{
353 | script{
354 | println("aborted")
355 | gitlab.ChangeCommitStatus(projectId,commitSha,"canceled")
356 | toemail.Email("流水线被取消了!",userEmail)
357 | }
358 |
359 | }
360 |
361 | }
362 |
363 | }
364 | ```
365 |
366 | 接下来可以调试了,如果没有问题会在邮箱中看到此封邮件。
367 | 
368 |
369 |
370 | #### 过滤特殊push请求
371 | 你可能发现问题了,新建一个分支或者标签也会出现构建,这个构建是没有意义的。我们需要排除掉。没错,jenkins 的 `Generic webHook` 也是支持的。
372 |
373 | 参考官方的说明:https://github.com/jenkinsci/generic-webhook-trigger-plugin/tree/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd
374 |
375 | 
376 |
377 |
378 | 添加三个变量,获取当前的提交信息 `$object_kind $before $after`
379 | 
380 |
381 |
382 | 通过正则表达式配置触发条件:Expression `^push\s(?!0{40}).{40}\s(?!0{40}).{40}$` Text `$object_kind $before $after`。 push请求只有after和before的值都不是40个0的时候触发构建(为40个0的情况是删除分支或者新建分支)
383 |
384 | 
385 |
386 | Ok! 提交流水线配置好了,可以玩耍了~。
387 |
388 | ### 合并流水线
389 | 关于合并流水线的配置之前要把提交流水线配置好,当提交流水线配置好了,合并流水线只需要修改一个配置。
390 |
391 | 当流水线成功后才可以合并:会检查原分支中的最后一次提交的状态是否为success。
392 |
393 | 
394 |
395 | 当原分支最后一次提交的状态为success,则可以合并。
396 | 
397 |
398 | ---
399 |
400 |
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/04.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/05.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/06.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/07.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/08.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/09.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/10.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/11.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/12.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/13.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/14.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/15.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/16.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/17.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/18.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter03/images/19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter03/images/19.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-4 质量管理平台集成
3 | weight: 30
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本章主要我们主要学习与质量管理平台Sonarqube集成。
9 | {{% /notice %}}
10 |
11 |
12 |
13 | ### 目录
14 |
15 | + [认识sonarqube](#认识sonarqube)
16 | + [sonarqube配置管理](#sonarqube配置管理)
17 | + [项目分析](#项目分析)
18 | + [自动化分析](#自动化分析)
19 | + [sonarqube接口](#sonarqube接口)
20 | + [配置多分支](#配置多分支)
21 |
22 | ---
23 |
24 | ### 认识sonarqube
25 |
26 | #### 架构
27 |
28 | * 一台SonarQube Server启动3个主要过程:
29 | - Web服务器,供开发人员,管理人员浏览高质量的快照并配置SonarQube实例
30 | - 基于Elasticsearch的Search Server从UI进行后退搜索
31 | - Compute Engine服务器,负责处理代码分析报告并将其保存在SonarQube数据库中
32 |
33 | * 一个SonarQube数据库要存储:
34 | - SonarQube实例的配置(安全性,插件设置等)
35 | - 项目,视图等的质量快照。
36 | * 服务器上安装了多个SonarQube插件,可能包括语言,SCM,集成,身份验证和管理插件
37 | * 在构建/持续集成服务器上运行一个或多个SonarScanner,以分析项目
38 |
39 |
40 | 
41 |
42 | #### 工作原理
43 | 开发人员在IDE开发代码,可以安装SonarLint插件进行提交前代码扫描
44 | 当开发人员提交代码到版本控制系统中,自动触发jenkins进行代码扫描
45 |
46 | 
47 |
48 |
49 | #### 版本
50 | 开源社区版、开发版、企业版、数据中心版
51 | 
52 |
53 |
54 | #### 安装
55 | 我们这里使用Docker运行一个测试的环境,可以参考博客安装
56 | 博文地址: https://www.cnblogs.com/mascot1/p/11179767.html
57 |
58 | ```bash
59 | docker run --rm -d --name sonarqube \
60 | -p 9000:9000 \
61 | -v ${LOCALDIR}/sonar/sonarqube_conf:/opt/sonarqube/conf \
62 | -v ${LOCALDIR}/sonar/sonarqube_extensions:/opt/sonarqube/extensions \
63 | -v ${LOCALDIR}/sonar/sonarqube_logs:/opt/sonarqube/logs \
64 | -v ${LOCALDIR}/sonar/sonarqube_data:/opt/sonarqube/data \
65 | sonarqube:7.9.2-community
66 | ```
67 |
68 | WEB 页面 http://127.0.0.1:9000
69 |
70 | 
71 |
72 |
73 |
74 | ### sonarqube配置管理
75 |
76 | #### 强制登录
77 | 默认所有项目都可以公开的查看,在企业内肯定要配置成私有的。只有登录后才能查看。
78 | 
79 |
80 |
81 | #### ldap集成
82 | 安装LDAP插件
83 | 
84 |
85 | 不用找了哦,页面上没有LDAP配置。需要修改sonar配置文件,然后重启服务器。
86 |
87 | ```
88 | #LDAP settings
89 | #admin
90 | sonar.security.realm=LDAP
91 | ldap.url=ldap://192.168.1.200:389
92 | ldap.bindDn=cn=admin,dc=devops,dc=com
93 | ldap.bindPassword=ldap12344
94 | #users
95 | ldap.user.baseDn=ou=jenkins,dc=devops,dc=com
96 | ldap.user.request=(&(objectClass=inetOrgPerson)(cn={login}))
97 | ldap.user.realNameAttribute=cn
98 | ldap.user.emailAttribute=mail
99 | ```
100 | #### gitlab认证集成
101 |
102 | 安装GitlabAuth插件
103 | 
104 |
105 | 在gitlab中创建一个应用 系统设置 应用管理,填写`http://sonarserver:9000/oauth2/callback/gitlab`
106 |
107 | 
108 | 
109 |
110 |
111 | 接下来在sonarqube中配置gitlab信息。这个真的有图形页面,可以直接配置。主要填写gitlab的信息。
112 |
113 | 
114 |
115 | 登录时出现此选项表明成功了
116 | 
117 |
118 |
119 | #### github认证集成
120 | 安装GithubAuth插件
121 | 
122 |
123 |
124 | 在github中创建一个应用 系统设置 应用管理,填写`http://sonarserver:9000/oauth2/callback`
125 |
126 | 
127 |
128 | 接下来在sonarqube中配置
129 | 
130 |
131 | 最终效果
132 | 
133 |
134 |
135 | ### 项目分析
136 |
137 | #### 安装配置sonarscanner
138 | 下载地址:https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
139 |
140 | 
141 |
142 | ```
143 | tar zxf sonar-scanner-xxxx.tar.gz -C /usr/local
144 |
145 | vim /etc/profile
146 |
147 | export SCANNER_HOME=/usr/local/sonar-scannerxxx
148 | export PATH=$PATH:$SCANNER_HOME/bin
149 |
150 | source /etc/profile
151 | ```
152 |
153 |
154 | #### 本地分析项目
155 |
156 | `sonar.projectKey` 指定项目的关键字,`sonar.host.url`指定服务器地址(可以直接在配置文件中写死),`projectName`指定项目的名称, `projectVersion`指定项目的版本(可以用构建时间和构建ID定义),`login`指定登录用户名,`password`指定登录用户密码, `projectDescription`指定项目的描述信息, `links.homepage`指定项目的主页(超链接), `sources`指定扫描的目录, `sourceEncoding`指定扫描时的编码, `java.binaries`指定编译后的类文件目录(必填), `java.test.binaries`指定编译后的测试类目录,`java.surefire.report`指定测试报告目录。
157 |
158 | ```bash
159 | sonar-scanner -Dsonar.host.url=http://192.168.1.200:9000 \
160 | -Dsonar.projectKey=demo-maven-service \
161 | -Dsonar.projectName=demo-maven-service \
162 | -Dsonar.projectVersion=1.0 \
163 | -Dsonar.login=admin \
164 | -Dsonar.password=admin \
165 | -Dsonar.ws.timeout=30 \
166 | -Dsonar.projectDescription="my first project!" \
167 | -Dsonar.links.homepage=http://www.baidu.com \
168 | -Dsonar.sources=src \
169 | -Dsonar.sourceEncoding=UTF-8 \
170 | -Dsonar.java.binaries=target/classes \
171 | -Dsonar.java.test.binaries=target/test-classes \
172 | -Dsonar.java.surefire.report=target/surefire-reports
173 | ```
174 |
175 |
176 | ### 自动化分析
177 |
178 | 在jenkins中安装插件`sonarqube scanner` 配置SonarQube服务器:登录Jenkins,然后转到“ 管理Jenkins”>“配置系统”。
179 | 向下滚动到SonarQube配置部分,单击Add SonarQube,然后添加提示您的值。
180 | 服务器身份验证令牌应创建为“机密文本”凭据。
181 |
182 | 
183 |
184 |
185 | 首先我们在共享库中定义一个sonarqube.groovy,用与扫描。新建文件`src/org/devops/sonarqube.groovy` 在这里我们定义了一个服务器列表,用于选择本次扫描使用的服务器(存在多个sonar的时候很有用处) 使用`withSonarQubeEnv`使用在Jenkins中配置sonar环境。这个方法有5个参数`服务器类型、项目名称、项目描述、项目扫描路径、分支名称`。
186 |
187 |
188 | ```
189 | package org.devops
190 |
191 |
192 | //scan
193 | def SonarScan(sonarServer,projectName,projectDesc,projectPath,branchName){
194 |
195 | //定义sonar服务器列表
196 | def servers = ["test":"sonarqube-test","prod":"sonarqube-prod"]
197 |
198 | //使用sonar服务器
199 | withSonarQubeEnv("${servers[sonarServer]}"){
200 |
201 | def scannerHome = "/home/jenkins/buildtools/sonar-scanner-3.2.0.1227-linux/"
202 | def sonarDate = sh returnStdout: true, script: 'date +%Y%m%d%H%M%S'
203 | sonarDate = sonarDate - "\n"
204 |
205 | sh """
206 | ${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=${projectName} \
207 | -Dsonar.projectName=${projectName} -Dsonar.projectVersion=${sonarDate} -Dsonar.ws.timeout=30 \
208 | -Dsonar.projectDescription=${projectDesc} -Dsonar.links.homepage=http://www.baidu.com \
209 | -Dsonar.sources=${projectPath} -Dsonar.sourceEncoding=UTF-8 -Dsonar.java.binaries=target/classes \
210 | -Dsonar.java.test.binaries=target/test-classes -Dsonar.java.surefire.report=target/surefire-reports -Dsonar.branch.name=${branchName} -X
211 | """
212 | }
213 | }
214 |
215 | ```
216 |
217 | 在Jenkinsfile中引用: 我们首先加载`jenkinslibrary`共享库,引用`sonarqube.groovy`。
218 |
219 | ```#!groovy
220 |
221 | @Library('jenkinslibrary@master') _
222 |
223 | //func from shareibrary
224 | def sonar = new org.devops.sonarqube()
225 |
226 |
227 | pipeline {
228 | agent any
229 |
230 | stages {
231 | stage("codescan"){
232 | steps{
233 | script{
234 | sonar.SonarScan("test","${JOB_NAME}","${JOB_NAME}","src")
235 | }
236 | }
237 | }
238 | }
239 |
240 | }
241 | ```
242 | 效果:此时流水线运行完成后,在项目中可以看到Sonarqube的链接。点击即可进入sonarqube
243 | 
244 |
245 | 项目的扫描结果
246 | 
247 | 
248 |
249 |
250 |
251 |
252 |
253 | ### sonarqube接口
254 | 根据sonar官方的文档获取接口使用详情。
255 |
256 | ```
257 | //查找项目
258 | api/projects/search?projects=${projectName}"
259 |
260 | //创建项目
261 | api/projects/create?name=${projectName}&project=${projectName}"
262 |
263 | //更新语言规则集
264 | api/qualityprofiles/add_project?language=${language}&qualityProfile=${qualityProfile}&project=${projectName}"
265 |
266 | //项目授权
267 | api/permissions/apply_template?projectKey=${projectKey}&templateName=${templateName}"
268 |
269 | //更新质量阈
270 | api/qualitygates/select?projectKey=${projectKey}&gateId=${gateId}"
271 |
272 | ```
273 |
274 |
275 | 封装到共享库中`sonarapi.groovy`
276 |
277 | ```
278 | package org.devops
279 |
280 |
281 | //封装HTTP
282 |
283 | def HttpReq(reqType,reqUrl,reqBody){
284 | def sonarServer = "http://192.168.1.200:30090/api"
285 |
286 | result = httpRequest authentication: 'sonar-admin-user',
287 | httpMode: reqType,
288 | contentType: "APPLICATION_JSON",
289 | consoleLogResponseBody: true,
290 | ignoreSslErrors: true,
291 | requestBody: reqBody,
292 | url: "${sonarServer}/${reqUrl}"
293 | //quiet: true
294 |
295 | return result
296 | }
297 |
298 |
299 | //获取Sonar质量阈状态
300 | def GetProjectStatus(projectName){
301 | apiUrl = "project_branches/list?project=${projectName}"
302 | response = HttpReq("GET",apiUrl,'')
303 |
304 | response = readJSON text: """${response.content}"""
305 | result = response["branches"][0]["status"]["qualityGateStatus"]
306 |
307 | //println(response)
308 |
309 | return result
310 | }
311 |
312 | //搜索Sonar项目
313 | def SerarchProject(projectName){
314 | apiUrl = "projects/search?projects=${projectName}"
315 | response = HttpReq("GET",apiUrl,'')
316 |
317 | response = readJSON text: """${response.content}"""
318 | result = response["paging"]["total"]
319 |
320 | if(result.toString() == "0"){
321 | return "false"
322 | } else {
323 | return "true"
324 | }
325 | }
326 |
327 | //创建Sonar项目
328 | def CreateProject(projectName){
329 | apiUrl = "projects/create?name=${projectName}&project=${projectName}"
330 | response = HttpReq("POST",apiUrl,'')
331 | println(response)
332 | }
333 |
334 | //配置项目质量规则
335 |
336 | def ConfigQualityProfiles(projectName,lang,qpname){
337 | apiUrl = "qualityprofiles/add_project?language=${lang}&project=${projectName}&qualityProfile=${qpname}"
338 | response = HttpReq("POST",apiUrl,'')
339 | println(response)
340 | }
341 |
342 |
343 | //获取质量阈ID
344 | def GetQualtyGateId(gateName){
345 | apiUrl= "qualitygates/show?name=${gateName}"
346 | response = HttpReq("GET",apiUrl,'')
347 | response = readJSON text: """${response.content}"""
348 | result = response["id"]
349 |
350 | return result
351 | }
352 |
353 | //配置项目质量阈
354 |
355 | def ConfigQualityGates(projectName,gateName){
356 | gateId = GetQualtyGateId(gateName)
357 | apiUrl = "qualitygates/select?gateId=${gateId}&projectKey=${projectName}"
358 | response = HttpReq("POST",apiUrl,'')
359 | println(response)println(response)
360 | }
361 |
362 | ```
363 |
364 |
365 | 应用实践:
366 |
367 | ```
368 | stage("QA"){
369 | steps {
370 | script{
371 | //搜索项目
372 | result = sonarapi.SerarchProject("${JOB_NAME}")
373 | println(result)
374 |
375 | //判断项目是否存在
376 | if (result == "false"){
377 | println("${JOB_NAME}---项目不存在,准备创建项目---> ${JOB_NAME}!")
378 | sonarapi.CreateProject("${JOB_NAME}")
379 | } else {
380 | println("${JOB_NAME}---项目已存在!")
381 | }
382 |
383 | //配置项目质量规则
384 | qpName="${JOB_NAME}".split("-")[0] //Sonar%20way
385 | sonarapi.ConfigQualityProfiles("${JOB_NAME}","java",qpName)
386 |
387 | //配置质量阈
388 | sonarapi.ConfigQualityGates("${JOB_NAME}",qpName)
389 |
390 | //代码扫描
391 | sonar.SonarScan("test","${JOB_NAME}","${JOB_NAME}","src")
392 |
393 |
394 | sleep 30
395 | //获取扫描结果
396 | result = sonarapi.GetProjectStatus("${JOB_NAME}")
397 |
398 |
399 | println(result)
400 | if (result.toString() == "ERROR"){
401 | error " 代码质量阈错误!请及时修复!"
402 | } else {
403 | println(result)
404 | }
405 | }
406 | }
407 | }
408 |
409 |
410 | ```
411 |
412 |
413 | ### 配置多分支
414 |
415 | 将插件放到两个目录中,然后重启sonar
416 |
417 | 
418 |
419 | 扫描参数增加 –Dsonar.branch.name=
420 | 
421 |
422 | 效果
423 | 
424 |
425 |
426 |
427 | ---
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/04.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/05.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/06.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/07.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/08.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/09.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/10.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/11.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/12.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/13.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/14.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/15.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/16.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/17.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/18.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/19.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/20.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/21.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/21.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/22.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/22.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter04/images/23.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter04/images/23.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-5 制品仓库集成
3 | weight: 35
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本章我们主要讲述Jenkins与制品库nexus、artiifactory集成,上传下载制品。
9 | {{% /notice %}}
10 |
11 |
12 |
13 | ### 目录
14 | + [部署](#部署)
15 | + [功能](#功能)
16 | + [基本概念](#基本概念)
17 | + [上传制品](#上传制品)
18 | + [集成jenkins上传制品](#集成jenkins上传制品)
19 | + [使用nexus插件上传制品](#使用nexus插件上传制品)
20 | + [发布制品](#发布制品)
21 | + [nexus接口](#nexus接口)
22 | + [artifactory集成](#artifactory集成)
23 | - [构建制品](#构建制品)
24 | - [上传制品](#上传制品)
25 |
26 | ---
27 |
28 | ### 部署
29 |
30 | 测试环境使用Docker安装部署
31 |
32 | ```bash
33 | docker run -id \
34 | --privileged=true --name=nexus3 \
35 | -p 8081:8081 \
36 | -v ${LOCALDIR}/nexus3/nexus-data:/nexus-data \
37 | sonatype/nexus3:3.20.1
38 | ```
39 |
40 |
41 | 安装完成后默认的admin账号密码存储在了数据目录,获取初始化密码后更新账号密码。
42 | 
43 |
44 |
45 | ### 功能
46 | 私服仓库: 本地maven私服加快构建速度
47 | 代理仓库:将公网等第三方提供的仓库代理到本地
48 |
49 | 
50 |
51 |
52 |
53 | ### 基本概念
54 |
55 | 组件是一种资源,在构建过程中需要依赖。它可以是整个应用程序,也可以是静态资源(例如图片)。
56 | 通常,这些组件是各种文件的存档,包括:类文件中的Java字节码、C对象文件、文本文件、二进制文件。
57 | 组件的多种格式,例如:Java JAR,WAR,EAR格式;普通ZIP或.tar.gz文件;其他软件包格式,例如NuGet软件包,Ruby gems,NPM软件包;可执行文件格式,例如.exe 或.sh 文件,Android APK文件,各种安装程序格式。
58 | 
59 |
60 |
61 |
62 | 组件可以由多个嵌套组件本身组成。组件提供了所有构建块和功能。可以通过组装并添加自己的业务相关组件来创建功能强大的完整应用程序。在不同的工具链中,组件称为工件,程序包,捆绑包,归档和其他术语。概念和想法保持不变,组件用作通用术语。组件由一组特定值(坐标)标识。这些坐标的通用集是组,名称和版本的用法。这些坐标的名称和用法随所使用的工具链而变化。组件也可以成为其他元数据的基础
63 |
64 | 
65 |
66 |
67 | 资产 :例如Maven项目中的pom文件算是资产一部分,包含元数据的重要补充。
68 | 实际的存档文件(pom.xml)是与组件( jar/war包)关联的资产。但是,更复杂的格式具有与组件(jar包)关联的众多资产(pom)。例如,Maven存储库中的典型JAR组件至少由POM和JAR文件定义-两者均构成属于同一组件的单独资产。其他文件(例如JavaDoc或Sources JAR文件)是属于同一组件的资产。
69 | 另一方面,Docker格式为资产提供唯一的标识符,并将其称为Docker层。这些资产可用于不同的组件-Docker映像。例如,一个Docker层可以是多个Docker映像引用的特定操作系统。
70 |
71 | 
72 |
73 |
74 | ### 上传制品
75 | 我们需要在nexus中创建一个新的仓库maven-hostd,同时我们需要在maven的配置文件`settings.xml`中配置maven-hostd认证。如下:
76 |
77 | ```
78 |
79 | maven-hostd
80 | admin
81 | admin123
82 |
83 | ```
84 |
85 | 注意使用mvn deploy 发布时,server.id == respository.id。
86 |
87 | 
88 | 
89 |
90 |
91 |
92 | ### 集成jenkins上传制品
93 |
94 | 步骤:获取Jar包名称、读取pom文件、获取坐标信息、使用mvn deploy上传。
95 |
96 |
97 | ```
98 | def jarName = sh returnStdout: true, script: "cd target;ls *.jar"
99 | jarName = jarName - "\n"
100 |
101 | def pom = readMavenPom file: 'pom.xml'
102 | pomVersion = "${pom.version}"
103 | pomArtifact = "${pom.artifactId}"
104 | pomPackaging = "${pom.packaging}"
105 | pomGroupId = "${pom.groupId}"
106 |
107 | println("${pomGroupId}-${pomArtifact}-${pomVersion}-${pomPackaging}")
108 |
109 | def mvnHome = tool "M2"
110 | sh """
111 | cd target/
112 | ${mvnHome}/bin/mvn deploy:deploy-file -Dmaven.test.skip=true \
113 | -Dfile=${jarName} -DgroupId=${pomGroupId} \
114 | -DartifactId=${pomArtifact} -Dversion=${pomVersion} \
115 | -Dpackaging=${pomPackaging} -DrepositoryId=maven-hostd \
116 | -Durl=http://192.168.1.200:30083/repository/maven-hostd
117 | """
118 | ```
119 |
120 |
121 |
122 | ### 使用nexus插件上传制品
123 |
124 | 安装nexus artifact uploader插件、使用片段生成器生成DSL。
125 |
126 | 
127 |
128 |
129 | 开始编写Jenkinsfile
130 | ```
131 | //use nexus plugin
132 | def repoName = "maven-hostd"
133 | def filePath = "target/${jarName}"
134 | nexusArtifactUploader artifacts: [[artifactId: "${pomArtifact}",
135 | classifier: '',
136 | file: "${filePath}",
137 | type: "${pomPackaging}"]],
138 | credentialsId: 'nexus-admin-user',
139 | groupId: "${pomGroupId}",
140 | nexusUrl: '192.168.1.200:30083',
141 | nexusVersion: 'nexus3',
142 | protocol: 'http',
143 | repository: "${repoName}",
144 | version: "${pomVersion}"
145 | ```
146 |
147 | 查看上传的日志
148 | 
149 | 查看仓库制品
150 | 
151 |
152 |
153 |
154 | ### 发布制品
155 | 安装`Maven Artifact ChoiceListProvider (Nexus)`插件
156 |
157 | 
158 |
159 |
160 | 用户选择制品,在应用服务器通过salt、ansible下载制品并部署
161 | 
162 |
163 |
164 |
165 | ### nexus接口
166 |
167 | ```
168 | package org.devops
169 |
170 |
171 | //封装HTTP
172 | def HttpReq(reqType,reqUrl,reqBody){
173 | def sonarServer = "http://192.168.1.200:30083/service/rest"
174 |
175 | result = httpRequest authentication: 'nexus-admin-user',
176 | httpMode: reqType,
177 | contentType: "APPLICATION_JSON",
178 | consoleLogResponseBody: true,
179 | ignoreSslErrors: true,
180 | requestBody: reqBody,
181 | url: "${sonarServer}/${reqUrl}",
182 | quiet: true
183 |
184 | return result
185 | }
186 |
187 |
188 | //获取仓库中所有组件
189 |
190 | def GetRepoComponents(repoName){
191 | apiUrl = "/v1/components?repository=${repoName}"
192 | response = HttpReq("GET",apiUrl,'')
193 |
194 | response = readJSON text: """${response.content}"""
195 | println(response["items"].size())
196 |
197 | return response["items"]
198 | }
199 |
200 |
201 | //获取单件组件
202 |
203 | def GetComponentsId(repoName,groupId,artifactId,version){
204 | println("获取单件组件ID")
205 | result = GetRepoComponents(repoName)
206 |
207 | for (component in result){
208 |
209 | if (component["group"] == groupId && component["name"] == artifactId && component["version"] == version ){
210 |
211 | componentId = component["id"]
212 |
213 | return componentId
214 | }
215 | }
216 |
217 | println(componentId)
218 | }
219 |
220 | //获取组件信息
221 | def GetSingleComponents(repoName,groupId,artifactId,version){
222 | println("获取单件组件信息")
223 | componentId = GetComponentsId(repoName,groupId,artifactId,version)
224 | apiUrl = "/v1/components/${componentId}"
225 | response = HttpReq("GET",apiUrl,'')
226 |
227 | response = readJSON text: """${response.content}"""
228 | println(response["assets"]["downloadUrl"])
229 | }
230 | ```
231 |
232 |
233 |
234 | ### artifactory集成
235 |
236 | 安装Artifactory插件,配置Artifactory仓库信息(仓库地址、用户认证信息)。
237 | 
238 |
239 |
240 | #### 构建制品
241 |
242 | ```
243 | package org.devops
244 |
245 | //Maven打包构建
246 | def MavenBuild(buildShell){
247 | def server = Artifactory.newServer url: "http://192.168.1.200:30082/artifactory"
248 | def rtMaven = Artifactory.newMavenBuild()
249 | def buildInfo
250 | server.connection.timeout = 300
251 | server.credentialsId = 'artifactory-admin-user'
252 | //maven打包
253 | rtMaven.tool = 'M2'
254 | buildInfo = Artifactory.newBuildInfo()
255 |
256 | String newBuildShell = "${buildShell}".toString()
257 | println(newBuildShell)
258 | rtMaven.run pom: 'pom.xml', goals: newBuildShell, buildInfo: buildInfo
259 | //上传build信息
260 | server.publishBuildInfo buildInfo
261 | }
262 |
263 |
264 | def main(buildType,buildShell){
265 | if(buildType == "mvn"){
266 | MavenBuild(buildShell)
267 | }
268 | }
269 | ```
270 |
271 | 查看构建数据:
272 | 
273 |
274 |
275 |
276 | 命名规范
277 |
278 | ```
279 | 仓库命名规范
280 | 业务/项目-环境类型 例如: demo-dev
281 |
282 | 制品命名规范
283 | 应用名称-版本号-构建ID.type
284 | 例如: demo-myapp-service-1.jar
285 |
286 | 制品目录规范
287 | 业务/项目
288 | 应用名称
289 | 版本号
290 | 制品
291 | ```
292 | 
293 |
294 |
295 |
296 | #### 上传制品
297 |
298 | ```
299 | rtUpload (
300 | serverId: "art1",
301 | spec:
302 | """{
303 | "files": [
304 | {
305 | "pattern": "target/${jarName}",
306 | "target": "${uploadDir}/"
307 | }
308 | ]
309 | }"""
310 | )
311 | ```
312 | 
313 |
314 |
315 |
316 | ---
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/04.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/05.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/06.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/07.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/08.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/09.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/10.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/11.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/12.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/13.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/14.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/15.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter05/images/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter05/images/16.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-6 需求管理平台集成
3 | weight: 40
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本章我们主要讲述Jenkins与需求管理平台Jira集成。这篇文章是我根据我们当前团队的情况进行定制的,可能有些内容与大家不太一样。重点是告诉大家如何实现集成?关于细节问题可自由定制。 在这里要告诉大家的是思路。
9 | {{% /notice %}}
10 |
11 |
12 |
13 | ### 目录
14 |
15 | + [工具链调研分析](#工具链调研分析)
16 | + [实践](#实践)
17 | + [总结](#总结)
18 |
19 | ---
20 |
21 | 在这里先说一下,当前的现状。我们使用Jira的Git插件能够实现在Jira上面新建Gitlab分支(实现需求与代码基线关联),这个操作需要手动完成。使用Jira中的Git插件实现集成,能够实现在Jira系统对应的任务下面创建分支,或开发人员在创建分支的时候分支名称包含Jira ID则可以自动关联。 通过上面的描述你应该发现了存在的一些问题,例如:插件不稳定,资源消耗大。手动创建分支,增加了人员成本。
22 |
23 |
24 | 来我们先看下当前的分支策略(每个团队可能会有自己的一套分支策略)。
25 | 
26 |
27 | 开发人员在特性分支进行开发,基于master分支创建一个版本分支(用于发布)。特性分支在特性环境验证通过后,将特性分支合并到版本分支,此时通过版本分支进行UAT测试环境、STAG预生产环境验证测试,测试通过通过版本分支发布PROD生产环境。生产环境发布完成后,将版本分支合并到master分支。
28 |
29 |
30 | 为解决上述问题,制作了改进方案。 我们想实现在Jira中创建故事或者任务(Jira中的issue)时自动在对应的代码库创建分支,故事或者任务在关联到发布(Jira中的release)之后自动在代码库中创建一个release分支和特性分支到release分支的合并请求。
31 |
32 |
33 | ### 工具链调研分析
34 | 其实我们需要配置的是通过Jira的Webhook 触发Jenkins来操作Gitlab系统。主要有三个点:
35 |
36 | * Jenkins项目配置触发器接收触发请求
37 | * Jira系统配置webHook触发Jenkins
38 | * Jenkins封装GitlabAPI完成相关操作
39 |
40 |
41 | #### Jira调研与分析-webhook
42 |
43 | 关于Jira的webhook挺强大的几乎所有的事件都能支持,我们进入jira系统的管理页面,选择webhook。
44 |
45 | 填写配置触发器URL(Jenkins项目触发器地址)、通过JQL(Jira的一种查询语言类似于SQL)配置触发的项目、选择触发事件。
46 |
47 | 
48 | 
49 |
50 | #### Jira调研与分析-webhookevent
51 |
52 | 在上面我们知道有webhook的概念,我们来分析要完成我们的需求所需要的事件类型。其实这些数据是在webhook中传递。Jira的事件类型如上图所示有很多,在这里我们用到了 问题创建`jira:issue_created`、问题更新`jira:issue_update`。
53 |
54 |
55 | * 创建任务或者故事属于`jira:issue_created`事件。
56 | * 任务或者故事关联上版本属于`jira:issue_updated`事件。
57 |
58 | 来一起看下Jira的webhook传递的JSON数据,如下图所示:
59 |
60 | 
61 |
62 |
63 | 到此可以总结为Jira的功能已经完全满足了我们的需求。
64 |
65 | #### Gitlab调研与分析
66 | 关于Gitlab要做的事情有2点,分别为:
67 |
68 | * 创建分支(branch)
69 | * 创建合并请求(merge request)
70 |
71 | 我们可以参考Gitlab的接口文档 https://docs.gitlab.com/ce/api/api_resources.html, 找出我们所需要的API。如下所示:
72 |
73 | ```bash
74 | # 获取项目ID接口
75 | api/v4/projects?search=projectName
76 | # 创建分支接口
77 | api/v4/projects/${projectId}/repository/branches?branch=${newBranch}&ref=${refBranch}
78 | # 创建合并请求接口
79 | api/v4/projects/${projectId}/merge_requests
80 | ```
81 |
82 | {{% notice info %}}
83 | 我们找到了以上三个接口,是不是疑问`获取项目ID接口`是用来做什么的呢? 其实这个就是用来通过项目名称获取项目的ID的。要想创建分支或者合并请求都是需要项目的ID的。项目名称就是Jira中的模块名称,也就是在Jira创建issue的时候必须要给此issue关联一个模块。后续我们根据此模块名称调用gitlab接口查询获取ID,以便进行后续的操作。
84 | {{% /notice %}}
85 |
86 | #### Jenkins调研与分析- Generic Webhook Trigger
87 |
88 | 我们使用` Generic Webhook Trigger`来完成此次任务, 对于Jenkins来说,需要做的有3点:
89 |
90 | * 配置触发器接收来自Jira的请求
91 | * 分析Jira请求中传递的数据
92 | * 封装Gitlab API完成相关操作
93 |
94 | **分析数据** 获取hook中参数-获取问题名称-获取模块名称等数据
95 | 
96 |
97 | **配置触发器** 生成项目唯一Token-使用项目名称标识
98 | 
99 |
100 | **配置触发过滤器** 过滤触发请求-限制只有故事任务等触发(在Jira中issue类型有很多种,这里可以灵活定义)
101 | 
102 |
103 |
104 |
105 |
106 | ### 实践
107 | 上面的技术点你是否清楚了呢? 接下来我们要上战场实践了。
108 |
109 | #### 创建issue自动创建gitlab分支
110 |
111 | **我想大概过程是这样的:**
112 |
113 | * Jira: 我来创建与gitlab项目名称一致的模块。然后我来创建issue关联上模块。
114 | * 此时通过webhook触发了Jenkins的项目。
115 | * Jenkins: 我来接收来自Jira的请求,我在请求中获取到`issueName,components`等参数。
116 | * Jenkins: 通过gitlab查询项目接口根据`components`来获取gitlab项目的ID。
117 | * Jenkins: 然后根据以获取的项目ID和`issueName`参数,通过gitlab创建分支接口创建分支。
118 |
119 |
120 | **技术实现细节是这样的**
121 |
122 | 要想实现在gitlab中创建分支,接口我们已经找到了,但是如何获取每个issue所关联的项目名称呢?我们自己维护一个关系表?当一个issue需要关联多个项目呢? 此时我们需要用到jira中的模块。使用jira中的模块来作为gitlab中的项目(命名一致),我们在创建issue的同时需要关联模块(必须关联,否则创建不了哦)。所以第一件事情是**在Jira中创建模块,模块命名同Gitlab项目名称**
123 |
124 |
125 | 此时我创建了一个模块`demo-maven-service`(我的gitlab项目名称也是这个)
126 | 
127 |
128 | 然后我(Jira)来创建issues,我创建一个任务,然后关联`demo-maven-service`模块 。此时证明:这个任务关联的是`demo-maven-service`这个代码库。也就是我要在`demo-maven-service`项目下创建一个`issueName`同名的分支(特性分支)。
129 |
130 | 
131 |
132 |
133 | 触发Jenkins项目: Jenkins 根据模块(components)在对应的仓库中创建分支(IssueName)。JIRA更新issues,Jenkins 根据模块(components)在对应的仓库中创建分支(issuesName)。
134 |
135 | 
136 | 
137 |
138 | 我的Jenkinsfile内容如下: 在这里我引入了我们自己封装好的`gitlab.groovy`,首先第一个步骤是`FileterData`分析数据,写了一个 `switch`语句来根据不同的`event`来获取不同的数据。`jira:issue_created`问题创建事件,我们需要获取的参数有**问题名称、触发人、关联模块、关联版本**。 然后第二个步骤是`CreateBranch`,我们通过gitlab的接口获取项目的ID,因为一个issue可能关联多个模块,所以这里是个list列表,后面遍历这个列表然后创建在对应的项目中创建分支。
139 |
140 | ```
141 | #!groovy
142 |
143 | @Library('jenkinslibrary') _
144 |
145 | def gitlab = new org.devops.gitlab()
146 |
147 | pipeline {
148 | agent { node { label "master"}}
149 |
150 |
151 | stages{
152 |
153 | stage("FileterData"){
154 | steps{
155 | script{
156 | response = readJSON text: """${webHookData}"""
157 |
158 | println(response)
159 |
160 | env.eventType = response["webhookEvent"]
161 |
162 | switch(eventType) {
163 | case "jira:issue_created":
164 | env.issueName = response['issue']['key']
165 | env.userName = response['user']['name']
166 | env.moduleNames = response['issue']['fields']['components']
167 | env.fixVersion = response['issue']['fields']['fixVersions']
168 | currentBuild.description = " Trigger by ${userName} ${eventType} ${issueName} "
169 | break
170 |
171 | default:
172 | println("hello")
173 | }
174 | }
175 | }
176 | }
177 |
178 | stage("CreateBranch"){
179 |
180 | when {
181 | anyOf {
182 | environment name: 'eventType', value: 'jira:issue_created' //issue 创建 /更新
183 | environment name: 'eventType', value: 'jira:issue_updated'
184 | }
185 | }
186 |
187 | steps{
188 | script{
189 | def projectIds = []
190 | println(issueName)
191 |
192 | //获取项目Id
193 | def projects = readJSON text: """${moduleNames}"""
194 | for ( project in projects){
195 | println(project["name"])
196 | projectName = project["name"]
197 | currentBuild.description += "\n project: ${projectName}"
198 | repoName = projectName.split("-")[0]
199 |
200 | try {
201 | projectId = gitlab.GetProjectID(repoName, projectName)
202 | println(projectId)
203 | projectIds.add(projectId)
204 | } catch(e){
205 | println(e)
206 | println("未获取到项目ID,请检查模块名称!")
207 | }
208 | }
209 |
210 | println(projectIds)
211 |
212 |
213 | for (id in projectIds){
214 | println("新建特性分支--> ${id} --> ${issueName}")
215 | currentBuild.description += "\n 新建特性分支--> ${id} --> ${issueName}"
216 | gitlab.CreateBranch(id,"master","${issueName}")
217 | }
218 | }
219 | }
220 | }
221 | }
222 | }
223 | ```
224 |
225 |
226 | 最终效果,登录gitlab进入项目中你应该能够看到跟当前issue同名的一个特性分支。
227 | 
228 |
229 |
230 | {{% notice info %}}
231 | 为了避免重复创建分支导致流水线失败,我们需要在写gitlab方法时加上一个try catch捕获异常。
232 | {{% /notice %}}
233 |
234 |
235 | #### 自动创建合并请求
236 | JIRA更新issues到版本中。 Jenkins根据issues中的模块信息,在对应的仓库中创建release分支(fixVersion),并创建特性分支(issueName)到release分支的MR。 jira的issue更新事件有两个情况第一种是增加关联的模块,还有一种是将issue关联了版本。
237 |
238 | 我们先来创建一个版本
239 | 
240 | 然后将issue关联一个版本
241 |
242 | 
243 |
244 | 完善Jenkinsfile
245 | ```#!groovy
246 |
247 | @Library('jenkinslibrary') _
248 |
249 | def gitlab = new org.devops.gitlab()
250 | pipeline {
251 | agent { node { label "master"}}
252 |
253 |
254 | stages{
255 |
256 | stage("FileterData"){
257 | steps{
258 | script{
259 | response = readJSON text: """${webHookData}"""
260 |
261 | println(response)
262 |
263 | env.eventType = response["webhookEvent"]
264 |
265 | switch(eventType) {
266 | case "jira:issue_created":
267 | env.issueName = response['issue']['key']
268 | env.userName = response['user']['name']
269 | env.moduleNames = response['issue']['fields']['components']
270 | env.fixVersion = response['issue']['fields']['fixVersions']
271 | currentBuild.description = " Trigger by ${userName} ${eventType} ${issueName} "
272 | break
273 |
274 | case "jira:issue_updated":
275 | env.issueName = response['issue']['key']
276 | env.userName = response['user']['name']
277 | env.moduleNames = response['issue']['fields']['components']
278 | env.fixVersion = response['issue']['fields']['fixVersions']
279 | currentBuild.description = " Trigger by ${userName} ${eventType} ${issueName} "
280 | break
281 |
282 | default:
283 | println("hello")
284 | }
285 | }
286 | }
287 | }
288 |
289 | stage("CreateBranchOrMR"){
290 |
291 | when {
292 | anyOf {
293 | environment name: 'eventType', value: 'jira:issue_created' //issue 创建 /更新
294 | environment name: 'eventType', value: 'jira:issue_updated'
295 | }
296 | }
297 |
298 | steps{
299 | script{
300 | def projectIds = []
301 | println(issueName)
302 | fixVersion = readJSON text: """${fixVersion}"""
303 | println(fixVersion.size())
304 |
305 | //获取项目Id
306 | def projects = readJSON text: """${moduleNames}"""
307 | for ( project in projects){
308 | println(project["name"])
309 | projectName = project["name"]
310 | currentBuild.description += "\n project: ${projectName}"
311 | repoName = projectName.split("-")[0]
312 |
313 | try {
314 | projectId = gitlab.GetProjectID(repoName, projectName)
315 | println(projectId)
316 | projectIds.add(projectId)
317 | } catch(e){
318 | println(e)
319 | println("未获取到项目ID,请检查模块名称!")
320 | }
321 | }
322 |
323 | println(projectIds)
324 |
325 |
326 | if (fixVersion.size() == 0) {
327 | for (id in projectIds){
328 | println("新建特性分支--> ${id} --> ${issueName}")
329 | currentBuild.description += "\n 新建特性分支--> ${id} --> ${issueName}"
330 | gitlab.CreateBranch(id,"master","${issueName}")
331 | }
332 |
333 |
334 |
335 | } else {
336 | fixVersion = fixVersion[0]['name']
337 | println("Issue关联release操作,Jenkins创建合并请求")
338 | currentBuild.description += "\n Issue关联release操作,Jenkins创建合并请求 \n ${issueName} --> RELEASE-${fixVersion}"
339 |
340 | for (id in projectIds){
341 |
342 | println("创建RELEASE-->${id} -->${fixVersion}分支")
343 | gitlab.CreateBranch(id,"master","RELEASE-${fixVersion}")
344 |
345 |
346 |
347 | println("创建合并请求 ${issueName} ---> RELEASE-${fixVersion}")
348 | gitlab.CreateMr(id,"${issueName}","RELEASE-${fixVersion}","${issueName}--->RELEASE-${fixVersion}")
349 |
350 | }
351 | }
352 | }
353 | }
354 | }
355 | }
356 | }
357 |
358 |
359 |
360 |
361 |
362 |
363 | ```
364 |
365 |
366 |
367 | Gitlab效果:查看合并请求
368 | 
369 | 
370 |
371 |
372 |
373 | ### 总结
374 | 通过以上两个实践,相信你已经知道了如何实现系统间的集成,没错主要是通过webhook和api。 接下来如果有需求可以独立去灵活定义了哦。
375 |
376 | ---
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/04.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/05.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/06.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/07.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/08.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/09.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/10.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/11.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/12.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/13.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/14.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/15.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/16.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter06/images/17.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter06/images/17.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter07/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter07/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter07/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-7 容器PaaS平台集成
3 | weight: 45
4 | ---
5 |
6 | {{% notice tip %}}
7 | 您好,本章我们主要讲述Jenkins与需求管理平台Jira集成。这篇文章是我根据我们当前团队的情况进行定制的,可能有些内容与大家不太一样。重点是告诉大家如何实现集成?关于细节问题可自由定制。 在这里要告诉大家的是思路。
8 | {{% /notice %}}
9 |
10 |
11 |
12 | ### 目录
13 |
14 | + [部署jenkins](#部署jenkins)
15 | + [静态slave](#静态slave)
16 | + [动态slave](#动态slave)
17 |
18 | ---
19 |
20 | 当前我做实验的集群是 v1.17.0。
21 |
22 | ### 部署jenkins
23 |
24 | 下载github仓库中的yml文件进行部署
25 | 文件地址: https://github.com/zeyangli/devops-on-k8s/blob/master/jenkins.yml
26 | 创建命令: kubectl create –f jenkins.yml
27 |
28 |
29 | 创建一个`Deployment`部署jenkins, 保留1个副本。 使用镜像`jenkins/jenkins:2.211`,开放端口30080,开发slave通信端口30081。volume以hostPath方式挂载到了容器中`JENKINS_HOME`。
30 |
31 | ```
32 | kind: Deployment
33 | apiVersion: apps/v1
34 | metadata:
35 | labels:
36 | k8s-app: jenkins
37 | name: jenkins
38 | namespace: devops
39 | spec:
40 | replicas: 1
41 | revisionHistoryLimit: 10
42 | selector:
43 | matchLabels:
44 | k8s-app: jenkins
45 | template:
46 | metadata:
47 | labels:
48 | k8s-app: jenkins
49 | namespace: devops
50 | name: jenkins
51 | spec:
52 | hostAliases:
53 | - ip: "192.168.1.200"
54 | hostnames:
55 | - "updates.jenkins-ci.org"
56 | containers:
57 | - name: jenkins
58 | image: jenkins/jenkins:2.211
59 | imagePullPolicy: Always
60 | ports:
61 | - containerPort: 30080
62 | name: web
63 | protocol: TCP
64 | - containerPort: 30081
65 | name: agent
66 | protocol: TCP
67 | resources:
68 | limits:
69 | cpu: 1000m
70 | memory: 2Gi
71 | requests:
72 | cpu: 500m
73 | memory: 512Mi
74 | livenessProbe:
75 | httpGet:
76 | path: /login
77 | port: 30080
78 | initialDelaySeconds: 60
79 | timeoutSeconds: 5
80 | failureThreshold: 12
81 | readinessProbe:
82 | httpGet:
83 | path: /login
84 | port: 30080
85 | initialDelaySeconds: 60
86 | timeoutSeconds: 5
87 | failureThreshold: 12
88 | volumeMounts:
89 | - name: jenkins-home
90 | mountPath: /var/lib/jenkins
91 | env:
92 | - name: JENKINS_HOME
93 | value: /var/lib/jenkins
94 | - name: JENKINS_OPTS
95 | value: --httpPort=30080
96 | - name: JENKINS_SLAVE_AGENT_PORT
97 | value: "30081"
98 | volumes:
99 | - name: jenkins-home
100 | hostPath:
101 | path: /data/devops/jenkins
102 | type: Directory
103 | serviceAccountName: jenkins
104 | ```
105 |
106 | 创建一个service,使用nodePort方式暴露端口
107 |
108 | ```
109 | ---
110 | kind: Service
111 | apiVersion: v1
112 | metadata:
113 | labels:
114 | k8s-app: jenkins
115 | name: jenkins
116 | namespace: devops
117 | spec:
118 | type: NodePort
119 | ports:
120 | - name: web
121 | port: 30080
122 | targetPort: 30080
123 | nodePort: 30080
124 | - name: slave
125 | port: 30081
126 | targetPort: 30081
127 | nodePort: 30081
128 | selector:
129 | k8s-app: jenkins
130 | ```
131 |
132 | 创建RBAC,授权。
133 |
134 | ```
135 | ---
136 | apiVersion: v1
137 | kind: ServiceAccount
138 | metadata:
139 | labels:
140 | k8s-app: jenkins
141 | name: jenkins
142 | namespace: devops
143 |
144 | ---
145 | kind: Role
146 | apiVersion: rbac.authorization.k8s.io/v1beta1
147 | metadata:
148 | name: jenkins
149 | namespace: devops
150 | rules:
151 | - apiGroups: [""]
152 | resources: ["pods","configmaps","namespaces"]
153 | verbs: ["create","delete","get","list","patch","update","watch"]
154 | - apiGroups: [""]
155 | resources: ["pods/exec"]
156 | verbs: ["create","delete","get","list","patch","update","watch"]
157 | - apiGroups: [""]
158 | resources: ["pods/log"]
159 | verbs: ["get","list","watch"]
160 | - apiGroups: [""]
161 | resources: ["secrets"]
162 | verbs: ["get"]
163 | ---
164 | apiVersion: rbac.authorization.k8s.io/v1beta1
165 | kind: RoleBinding
166 | metadata:
167 | name: jenkins
168 | namespace: devops
169 | roleRef:
170 | apiGroup: rbac.authorization.k8s.io
171 | kind: Role
172 | name: jenkins
173 | subjects:
174 | - kind: ServiceAccount
175 | name: jenkins
176 | namespace: devops
177 | ```
178 |
179 |
180 | ### 静态slave
181 | 静态slave是在Kubernetes中创建一个固定的pod运行,跟之前我们用VM主机添加agent是一样的。
182 | 首先我们登陆Jenkins,创建一个agent,然后获取secret信息。
183 | 
184 |
185 | 我们创建一个`Deployment`部署slave。在这里使用的镜像是`jenkinsci/jnlp-slave:3.36-1`,我在这里挂载了Docker和kubectl方便在pod中构建镜像和使用kubectl命令。挂载本地的一个目录用于workspace。 定义了环境变量`JENKINS_URL,JENKINS_SECRET,JENKINS_AGENT_NAME,JENKINS_AGENT_WORKDIR`。
186 |
187 | ```
188 | ---
189 | kind: Deployment
190 | apiVersion: apps/v1
191 | metadata:
192 | labels:
193 | k8s-app: jenkinsagent
194 | name: jenkinsagent
195 | namespace: devops
196 | spec:
197 | replicas: 1
198 | revisionHistoryLimit: 10
199 | selector:
200 | matchLabels:
201 | k8s-app: jenkinsagent
202 | template:
203 | metadata:
204 | labels:
205 | k8s-app: jenkinsagent
206 | namespace: devops
207 | name: jenkinsagent
208 | spec:
209 | containers:
210 | - name: jenkinsagent
211 | image: jenkinsci/jnlp-slave:3.36-1
212 | securityContext:
213 | privileged: true
214 | imagePullPolicy: IfNotPresent
215 | resources:
216 | limits:
217 | cpu: 1000m
218 | memory: 2Gi
219 | requests:
220 | cpu: 500m
221 | memory: 512Mi
222 | volumeMounts:
223 | - name: jenkinsagent-workdir
224 | mountPath: /home/jenkins/workspace
225 | - name: buildtools
226 | mountPath: /home/jenkins/buildtools
227 | - name: dockersock
228 | mountPath: "/var/run/docker.sock"
229 | - name: dockercmd
230 | mountPath: /usr/bin/docker
231 | - name: kubectlconfig
232 | mountPath: /home/jenkins/.kube/config
233 | - name: kubectlcmd
234 | mountPath: /usr/bin/kubectl
235 | env:
236 | - name: JENKINS_URL
237 | value: http://192.168.1.200:30080
238 | - name: JENKINS_SECRET
239 | value: 5639cac0bf16bf15735d44bc435793417365f4dfa8fc72fb12737f3787091ae8
240 | - name: JENKINS_AGENT_NAME
241 | value: build01
242 | - name: JENKINS_AGENT_WORKDIR
243 | value: /home/jenkins/workspace
244 | volumes:
245 | - name: jenkinsagent-workdir
246 | hostPath:
247 | path: /data/devops/jenkins/workspace
248 | type: Directory
249 | - name: buildtools
250 | hostPath:
251 | path: /usr/local/buildtools
252 | type: Directory
253 | - name: kubectlconfig
254 | hostPath:
255 | path: /root/.kube/config
256 | - name: kubectlcmd
257 | hostPath:
258 | path: /usr/bin/kubectl
259 | - name: dockersock
260 | hostPath:
261 | path: /var/run/docker.sock
262 | - name: dockercmd
263 | hostPath:
264 | path: /usr/bin/docker
265 | ```
266 |
267 |
268 | ### 动态slave
269 | 安装kubernetes插件(安装完成后最好重启一下)。配置插件信息 系统设置 -> 最后面 Cloud ->增加一个云。
270 |
271 |
272 | **制作Kubernetes证书**
273 |
274 | * 进入集群服务器 .kube/config
275 | * 复制config文件中的certificate-authority-data内容,生成base64文件 ca.crt
276 | * 复制config文件中的client-certificate-data内容,生成base64文件 client.crt
277 | * 复制config文件中的client-key-data内容,生成base64文件 client.key
278 | - echo zzzzzzzzz | base64 –d > client.key
279 |
280 | * 生成证书(会输入密码需要记住后面jenkins需要配置)
281 | - openssl pkcs12 -export -out cert.pfx -inkey client.key -in client.crt -certfile ca.crt
282 | * 下载证书 cert.pfx
283 |
284 |
285 | **Jenkins新建凭据**
286 |
287 | 新建凭据 证书类型 上传刚刚下载的证书。并输入证书密码
288 | 
289 |
290 |
291 |
292 | 将ca.crt 内容复制到 服务证书key 选择证书凭据 测试连接
293 | 
294 |
295 | **编写Jenkinsfile测试**
296 |
297 | 文件地址: https://github.com/zeyangli/devops-on-k8s/blob/master/jenkinsfile/jenkinsslave.jenkinsfile
298 |
299 | 关于Jenkinsfile的写法还有一种使用`podtemplate`感觉只是对`yaml`做了包装,学习成本高于原生yaml。所以这里直接使用了`yaml`定义的。
300 |
301 | ```
302 | pipeline{
303 | agent{
304 | kubernetes{
305 | label "test01"
306 | cloud 'kubernetes'
307 | yaml '''
308 | ---
309 | kind: Pod
310 | apiVersion: v1
311 | metadata:
312 | labels:
313 | k8s-app: jenkinsagent
314 | name: jenkinsagent
315 | namespace: devops
316 | spec:
317 | containers:
318 | - name: jenkinsagent
319 | image: jenkinsci/jnlp-slave:3.36-1
320 | imagePullPolicy: IfNotPresent
321 | resources:
322 | limits:
323 | cpu: 1000m
324 | memory: 2Gi
325 | requests:
326 | cpu: 500m
327 | memory: 512Mi
328 | volumeMounts:
329 | - name: jenkinsagent-workdir
330 | mountPath: /home/jenkins/workspace
331 | - name: buildtools
332 | mountPath: /home/jenkins/buildtools
333 | env:
334 | - name: JENKINS_AGENT_WORKDIR
335 | value: /home/jenkins/workspace
336 | volumes:
337 | - name: jenkinsagent-workdir
338 | hostPath:
339 | path: /data/devops/jenkins/workspace
340 | type: Directory
341 | - name: buildtools
342 | hostPath:
343 | path: /usr/local/buildtools
344 | type: Directory
345 | '''
346 | }
347 | }
348 |
349 |
350 | stages{
351 | stage("test"){
352 | steps{
353 | script{
354 | sh "sleep 30"
355 | }
356 | }
357 | }
358 | }
359 | }
360 |
361 | ```
362 |
363 | 赶快运行一下吧! 相信你已经成功了。
364 |
365 | ---
--------------------------------------------------------------------------------
/pipelineintegrated/chapter07/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter07/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter07/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter07/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter07/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter07/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter07/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter07/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 3-8 自动化接口测试
3 | weight: 50
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本章我们主要讲述Jenkins+jmeter自动化接口测试。
9 | {{% /notice %}}
10 |
11 |
12 |
13 | ### 目录
14 |
15 | ---
16 |
17 | 接口测试定义为一种软件测试类型,用于验证两个不同软件系统之间的通信是否正确完成。集成两个组件的连接称为接口。计算机世界中的此接口可以是API,Web服务等之类的东西。这些连接服务或接口的测试称为接口测试。接口实际上是由一组命令,消息和其他允许设备与用户之间进行通信的属性组成的软件。
18 |
19 | ### 运行测试用例
20 |
21 | ```
22 | jmeter -n -t scripts/blog.jmx -l report.jtl
23 | -e -o report -Jjmeter.save.saveservice.output_format=csv
24 | ```
25 |
26 | 参数说明:
27 |
28 | * -n: 非GUI模式执行JMeter
29 | * -t: 执行测试文件所在的位置
30 | * -l: 指定生成测试结果的保存文件,jtl文件格式
31 | * -e: 测试结束后,生成测试报告-o: 指定测试报告的存放位置
32 |
33 | 看下运行的效果:测试报告已生成是HTML文件,可直接打开。
34 |
35 | 
36 |
37 | 
38 |
39 |
40 | ### 批量运行用例
41 |
42 | 我们可以使用ant与Jmeter集成build.xml部分内容。 仓库地址:https://github.com/zeyangli/jmetertest.git
43 |
44 | ```xml
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | ```
76 |
77 | 运行用例
78 |
79 | ```
80 | Password:
81 | Buildfile: /Users/zeyang/Desktop/jmetertest-master/build.xml
82 |
83 | run:
84 |
85 | test:
86 | [jmeter] Executing test plan: /Users/zeyang/Desktop/jmetertest-master/scripts/blog.jmx ==> /Users/zeyang/Desktop/jmetertest-master/result/jtlfile/TestReport_202001100820.jtl
87 | [jmeter] Creating summariser
88 | [jmeter] Created the tree successfully using /Users/zeyang/Desktop/jmetertest-master/scripts/blog.jmx
89 | [jmeter] Starting the test @ Fri Jan 10 08:20:26 CST 2020 (1578615626561)
90 | [jmeter] Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
91 | [jmeter] summary = 2 in 00:00:00 = 8.2/s Avg: 64 Min: 59 Max: 70 Err: 0 (0.00%)
92 | [jmeter] Tidying up ... @ Fri Jan 10 08:20:27 CST 2020 (1578615627287)
93 | [jmeter] ... end of run
94 |
95 | report:
96 | [xslt] Processing /Users/zeyang/Desktop/jmetertest-master/result/jtlfile/TestReport_202001100820.jtl to /Users/zeyang/Desktop/jmetertest-master/result/htmlfile/202001100820_DetailReport.html
97 | [xslt] Loading stylesheet /usr/local/apache-jmeter-5.1.1/extras/jmeter.results.shanhe.me.xsl
98 | [xslt] Processing /Users/zeyang/Desktop/jmetertest-master/result/jtlfile/TestReport_202001100820.jtl to /Users/zeyang/Desktop/jmetertest-master/result/htmlfile/202001100820_SummaryReport.html
99 | [xslt] Loading stylesheet /usr/local/apache-jmeter-5.1.1/extras/jmeter-results-detail-report_21.xsl
100 |
101 | BUILD SUCCESSFUL
102 | Total time: 3 seconds
103 |
104 | ```
105 |
106 |
107 | 测试报告
108 |
109 | 
110 |
111 | 
112 |
113 |
114 |
115 | ### 自动化测试
116 |
117 | 使用Jenkins集成ant 和jmeter进行接口测试,直接看Jenkinsfile吧。我们可以理解为执行了ant的构建命令去运行接口测试,然后通过`publishHtml`展示测试报告。
118 |
119 | 
120 | ```
121 | #!groovy
122 |
123 | @Library('jenkinslibrary@master') _
124 |
125 | //func from shareibrary
126 | def build = new org.devops.build()
127 | def tools = new org.devops.tools()
128 | def toemail = new org.devops.toemail()
129 |
130 |
131 | //env
132 | String buildType = "${env.buildType}"
133 | String buildShell = "${env.buildShell}"
134 | String srcUrl = "${env.srcUrl}"
135 | String branchName = "${env.branchName}"
136 |
137 | userEmail = "2560350642@qq.com"
138 |
139 |
140 | //pipeline
141 | pipeline{
142 | agent { node { label "build"}}
143 |
144 |
145 | stages{
146 |
147 | stage("CheckOut"){
148 | steps{
149 | script{
150 |
151 |
152 | println("${branchName}")
153 |
154 | tools.PrintMes("获取代码","green")
155 | checkout([$class: 'GitSCM', branches: [[name: "${branchName}"]],
156 | doGenerateSubmoduleConfigurations: false,
157 | extensions: [],
158 | submoduleCfg: [],
159 | userRemoteConfigs: [[credentialsId: 'gitlab-admin-user', url: "${srcUrl}"]]])
160 |
161 | }
162 | }
163 | }
164 | stage("Build"){
165 | steps{
166 | script{
167 |
168 | tools.PrintMes("执行打包","green")
169 | build.Build(buildType,buildShell)
170 |
171 |
172 |
173 | //展示测试报告
174 | publishHTML([allowMissing: false,
175 | alwaysLinkToLastBuild: false,
176 | keepAll: false,
177 | reportDir: 'result/htmlfile',
178 | reportFiles: 'SummaryReport.html,DetailReport.html',
179 | reportName: 'InterfaceTestReport',
180 | reportTitles: ''])
181 | }
182 | }
183 | }
184 | }
185 | post {
186 | always{
187 | script{
188 | println("always")
189 | }
190 | }
191 |
192 | success{
193 | script{
194 | println("success")
195 | toemail.Email("流水线成功",userEmail)
196 |
197 | }
198 |
199 | }
200 | failure{
201 | script{
202 | println("failure")
203 | toemail.Email("流水线失败了!",userEmail)
204 | }
205 | }
206 |
207 | aborted{
208 | script{
209 | println("aborted")
210 | toemail.Email("流水线被取消了!",userEmail)
211 | }
212 |
213 | }
214 |
215 | }
216 | }
217 | ```
218 |
219 | ---
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/images/.DS_Store
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/images/01.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/images/02.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/images/03.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/images/04.png
--------------------------------------------------------------------------------
/pipelineintegrated/chapter08/images/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelineintegrated/chapter08/images/05.png
--------------------------------------------------------------------------------
/pipelinesyntax/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 流水线核心语法
3 | weight: 10
4 | pre: "2. "
5 | chapter: true
6 | ---
7 |
8 | ### Chapter 2
9 |
10 | # 流水线核心语法
11 |
12 |
13 | {{% notice tip %}}
14 | 😺您好,本模块主要讲解Jenkins 流水线核心语法!
15 | {{% /notice %}}
16 |
17 |
18 | | 章节名称 | 章节内容 |
19 | | ------ | ----------- |
20 | | [2-1 编写jenkinsfile](chapter01/index.en.md) |本章我们将介绍Jenkinsfile的语法 让大家认识流水线编写|
21 | | [2-2 Jenkins流水线语法](chapter02/index.en.md) | 本章我们将为大家详细讲述流水线语法|
22 | | [2-3 Jenkins共享库应用](chapter03/index.en.md) |本章我们将主要学习Jenkins共享库的配置|
23 | | [2-4 Groovy基础语法](chapter04/index.en.md) | 本章主要讲述Groovy编程基础语法|
24 | | [2-5 流水线开发工具](chapter05/index.en.md) | 本章我们主要讲述常用的流水线开发工具 |
25 |
26 |
--------------------------------------------------------------------------------
/pipelinesyntax/chapter01/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter01/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter01/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 开始编写Jenkinsfile
3 | weight: 15
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,还在疑惑什么是流水线吗? 本章我们将告诉您如何运行一条流水线 赶快学习吧! 😀
9 | {{% /notice %}}
10 |
11 | ### 目录
12 |
13 | + [为什么使用pipeline?](#为什么使用pipeline?)
14 | + [pipeline定义](#pipeline定义)
15 | + [pipeline演示](#pipeline演示)
16 | + [验证流水线效果](#验证流水线效果)
17 |
18 |
19 |
20 | ---
21 |
22 |
23 | ### 为什么使用pipeline?
24 |
25 | 本质上,jenkins是一个自动化引擎,它支持许多自动模式。流水线向Jenkins添加了一组强大的工具,支持用例、简单的持续集成到全面的持续交付流水线。 通过对一系列的发布任务建立标准的模板,用户可以利用更多流水线的特性,比如:
26 |
27 | * 代码化: 流水线是在代码中实现的,通常会存放到源代码控制,使团队具有编辑、审查和更新他们项目的交付流水线的能力。
28 |
29 | * 耐用性:流水线可以从Jenkins的master节点重启后继续运行。
30 | * 可暂停的:流水线可以由人功输入或批准继续执行流水线。
31 | * 解决复杂发布: 支持复杂的交付流程。例如循环、并行执行。
32 | * 可扩展性: 支持扩展DSL和其他插件集成。
33 |
34 | 构建一个可扩展是Jenkins的核心价值,流水线可以通过ShareLibrary的方式来扩展。
35 |
36 | ### pipeline定义
37 |
38 | 关于Jenkins流水线的运行我们可以抽象一下,例如:可以把流水线(pipeline)想象成13号线地铁,把流水线的阶段(stage)想象成地铁的每一个站点,把流水线脚本(jenkinsfile)想象成地铁线路图。这就是流水线的多样性,每条线路都有不同的站点。
39 |
40 | 
41 |
42 |
43 | 现在地铁(Jenkins)已经有了,我们需要设计地铁的运行线路图(Jenkinsfile),在线路图中指定要经过的站点(stages)。这下你是否已经知道我们要运行一条流水线,需要先做什么呢? --编写jenkinsfile
44 |
45 |
46 | Pipeline
47 |
48 | * Jenkins的Pipeline通过Jenkinsfile进行描述(类似于Dockerfile)
49 | * Jenkinsfile是Jenkins的特性(pipeline as code)
50 | * Pipeline是Jenkins的核心功能,提供一组可扩展的工具。
51 | * 通过Pipeline 的DSL语法可以完成从简单到复杂的交付流水线实现。
52 |
53 | Jenkinsfile
54 |
55 | * Jenkinsfile使用两种语法进行编写,分别是声明式和脚本式。
56 | * 声明式和脚本式的流水线从根本上是不同的。
57 | * 声明式是jenkins流水线更友好的特性。
58 | * 脚本式的流水线语法,提供更丰富的语法特性。
59 | * 声明式流水线使编写和读取流水线代码更容易设计。
60 |
61 |
62 |
63 |
64 | ### pipeline演示
65 | 来我们一起看下这里的配置,看下Jenkinsfile的组成及每个部分的功能含义。
66 |
67 | * 使用agent{},指定node节点/workspace(定义好此流水线在某节点运行)
68 | * 指定options{}运行选项(定义好此流水线运行时的一些选项,例如输出日志的时间)
69 | * 指定stages{}(stages包含多个stage,stage包含steps。是流水线的每个步骤)
70 | * 指定post{}(定义好此流水线运行成功或者失败后,根据状态做一些任务)
71 |
72 |
73 | ```groovy
74 | pipeline{
75 | //指定运行此流水线的节点
76 | agent { node { label "build"}}
77 |
78 |
79 | //流水线的阶段
80 | stages{
81 |
82 | //阶段1 获取代码
83 | stage("CheckOut"){
84 | steps{
85 | script{
86 | println("获取代码")
87 | }
88 | }
89 | }
90 | stage("Build"){
91 | steps{
92 | script{
93 | println("运行构建")
94 | }
95 | }
96 | }
97 | }
98 | post {
99 | always{
100 | script{
101 | println("流水线结束后,经常做的事情")
102 | }
103 | }
104 |
105 | success{
106 | script{
107 | println("流水线成功后,要做的事情")
108 | }
109 |
110 | }
111 | failure{
112 | script{
113 | println("流水线失败后,要做的事情")
114 | }
115 | }
116 |
117 | aborted{
118 | script{
119 | println("流水线取消后,要做的事情")
120 | }
121 |
122 | }
123 | }
124 | }
125 | ```
126 |
127 |
128 | ### 验证流水线效果
129 |
130 |
131 | 查看Jenkins构建日志(正确效果)
132 | 
133 |
134 | 通过BlueOcean查看(如果没有BlueOcean图标,需要自行在插件中心安装插件)
135 | 
136 |
137 |
138 |
139 | 到此一个简单的Jenkinfile完成了! 后面我们来详细分析每个步骤的作用。
140 |
141 | ---
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/pipelinesyntax/chapter01/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter01/images/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter01/images/01-subwaybeijing.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter01/images/01-subwaybeijing.jpg
--------------------------------------------------------------------------------
/pipelinesyntax/chapter01/images/02-blueocean.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter01/images/02-blueocean.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter01/images/03-jenkinslog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter01/images/03-jenkinslog.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter02/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter02/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter02/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Jenkins流水线语法
3 | weight: 20
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本模块主要学习声明式流水线的核心语法,掌握核心语法便于编写Jenkinsfile 😀
9 | {{% /notice %}}
10 |
11 | ### 目录
12 |
13 | + [声明式流水线](#声明式流水线)
14 | + [agent代理](#agent代理)
15 | + [post运行后处理](#post运行后处理)
16 | + [stages阶段](#stages阶段)
17 | + [environment环境变量](#environment环境变量)
18 | + [options运行选项](#options运行选项)
19 | + [parameters参数](#parameters参数)
20 | + [trigger触发器](#trigger触发器)
21 | + [tool构建工具](#tool构建工具)
22 | + [input交互输入](#input交互输入)
23 | + [when条件判断](#when条件判断)
24 | + [parallel并行](#parallel并行)
25 | + [script脚本标签](#script脚本标签)
26 |
27 | ---
28 |
29 | ### 声明式流水线
30 | 声明式Pipleine是官方推荐的语法,声明式语法更加简洁。所有的声明式Pipeline都必须包含一个 pipeline块中,比如:
31 |
32 | ```
33 | pipeline {
34 | //run
35 | }
36 | ```
37 |
38 | 在声明式Pipeline中的基本语句和表达式遵循Groovy的语法。但是有以下例外:
39 |
40 | * 流水线顶层必须是一个块,特别是pipeline{}。
41 | * 不需要分号作为分割符,是按照行分割的。
42 | * 语句块只能由阶段、指令、步骤、赋值语句组成。例如: input被视为input()。
43 |
44 |
45 | ### agent代理
46 |
47 | `agent`指定了流水线的执行节点。
48 |
49 | ```
50 | agent { node { label 'labelname' }}
51 |
52 | aget { label ' labelname '}
53 | ```
54 |
55 |
56 | 参数:
57 |
58 | * any 在任何可用的节点上执行pipeline。none 没有指定agent的时候默认。
59 | * label 在指定标签上的节点上运行Pipeline。 node 允许额外的选项(自定义workspace)。
60 |
61 |
62 |
63 | ### post运行后处理
64 | 当流水线完成后根据完成的状态做一些任务。例如:构建失败后邮件通知
65 |
66 | ```
67 | post {
68 | always {
69 | echo 'I will always say Hello again!'
70 | }
71 |
72 | failure{
73 | email : xxxx@dxx.com
74 | }
75 | }
76 | ```
77 |
78 | 常用的状态:
79 |
80 | * always 无论流水线或者阶段的完成状态。
81 | * changed 只有当流水线或者阶段完成状态与之前不同时。
82 | * failure 只有当流水线或者阶段状态为"failure"运行。
83 | * success 只有当流水线或者阶段状态为"success"运行。
84 | * unstable 只有当流水线或者阶段状态为"unstable"运行。例如:测试失败。
85 | + aborted 只有当流水线或者阶段状态为"aborted "运行。例如:手动取消。
86 |
87 |
88 | ### stages阶段
89 |
90 | `stages`是流水线的整个运行阶段,包含一个或多个 `stage` , 建议 `stages` 至少包含一个 `stage`。
91 |
92 | ```
93 | stages {
94 | stage('Example') {
95 | steps {
96 | echo 'Hello World'
97 | }
98 | }
99 | }
100 | ```
101 |
102 |
103 | ### environment环境变量
104 | 定义流水线环境变量,可以定义在全局变量或者步骤中的局部变量。这取决于 environment 指令在流水线内的位置。
105 |
106 | ```
107 | agent any
108 |
109 | //全局变量
110 | environment {
111 | activeEnv = 'dev'
112 | }
113 | stages {
114 | stage('Example') {
115 |
116 | //局部变量
117 | environment {
118 | AN_ACCESS_KEY = credentials('my-prefined-secret-text')
119 | }
120 | steps {
121 | sh 'printenv'
122 | }
123 | }
124 | }
125 | ```
126 |
127 | ### options运行选项
128 | 定义流水线运行时的配置选项,流水线提供了许多选项, 比如buildDiscarder,但也可以由插件提供, 比如 timestamps。
129 |
130 | ```
131 | agent any
132 | options {
133 | timeout(time: 1, unit: 'HOURS')
134 | }
135 | stages {
136 | stage('Example') {
137 | steps {
138 | echo 'Hello World'
139 | }
140 | }
141 | }
142 |
143 | ```
144 |
145 | 其他部分参数:
146 |
147 | * buildDiscarder: 为最近的流水线运行的特定数量保存组件和控制台输出。
148 | * disableConcurrentBuilds: 不允许同时执行流水线。 可被用来防止同时访问共享资源等。
149 | * overrideIndexTriggers: 允许覆盖分支索引触发器的默认处理。
150 | * skipDefaultCheckout: 在agent 指令中,跳过从源代码控制中检出代码的默认情况。
151 | * skipStagesAfterUnstable: 一旦构建状态变得UNSTABLE,跳过该阶段。
152 | * checkoutToSubdirectory: 在工作空间的子目录中自动地执行源代码控制检出。
153 | * timeout: 设置流水线运行的超时时间, 在此之后,Jenkins将中止流水线。
154 | * retry: 在失败时, 重新尝试整个流水线的指定次数。
155 | * timestamps 预测所有由流水线生成的控制台输出,与该流水线发出的时间一致。
156 |
157 |
158 | ### parameters参数
159 |
160 | 为流水线运行时设置项目相关的参数,就不用在UI界面上定义了,比较方便。
161 |
162 | ```
163 | //string 字符串类型的参数, 例如:
164 | parameters { string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '') }
165 |
166 | //booleanParam 布尔参数, 例如:
167 | parameters { booleanParam(name: 'DEBUG_BUILD', defaultValue: true, description: '') }
168 |
169 | ```
170 |
171 | ```
172 | agent any
173 | parameters {
174 | string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
175 | }
176 | stages {
177 | stage('Example') {
178 | steps {
179 | echo "Hello ${params.PERSON}"
180 | }
181 | }
182 | }
183 | ```
184 |
185 |
186 | ### trigger触发器
187 | 构建触发器
188 |
189 | ```
190 | //cron 计划任务定期执行构建。
191 | triggers { cron('H */4 * * 1-5') }
192 |
193 |
194 | //pollSCM 与cron定义类似,但是由jenkins定期检测源码变化。
195 | triggers { pollSCM('H */4 * * 1-5') }
196 |
197 |
198 |
199 |
200 | agent any
201 | triggers {
202 | cron('H */4 * * 1-5')
203 | }
204 | stages {
205 | stage('Example') {
206 | steps {
207 | echo 'Hello World'
208 | }
209 | }
210 | }
211 | ```
212 |
213 |
214 | ### tool构建工具
215 |
216 | 构建工具maven、ant、gradle,获取通过自动安装或手动放置工具的环境变量。支持maven/jdk/gradle。工具的名称必须在系统设置->全局工具配置中定义。
217 |
218 | ```
219 | agent any
220 | tools {
221 | maven 'apache-maven-3.0.1'
222 | }
223 | stages {
224 | stage('Example') {
225 | steps {
226 | sh 'mvn --version'
227 | }
228 | }
229 | }
230 | ```
231 |
232 |
233 | ### input交互输入
234 | input用户在执行各个阶段的时候,由人工确认是否继续进行。
235 |
236 | ```
237 | agent any
238 | stages {
239 | stage('Example') {
240 | input {
241 | message "Should we continue?"
242 | ok "Yes, we should."
243 | submitter "alice,bob"
244 | parameters {
245 | string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
246 | }
247 | }
248 | steps {
249 | echo "Hello, ${PERSON}, nice to meet you."
250 | }
251 | }
252 | }
253 | ```
254 |
255 | 参数解释:
256 |
257 | * message 呈现给用户的提示信息。
258 | * id 可选,默认为stage名称。
259 | * ok 默认表单上的ok文本。
260 | * submitter 可选的,以逗号分隔的用户列表或允许提交的外部组名。默认允许任何用户。
261 | * submitterParameter 环境变量的可选名称。如果存在,用submitter 名称设置。
262 | * parameters 提示提交者提供的一个可选的参数列表。
263 |
264 |
265 |
266 |
267 |
268 | ### when条件判断
269 | when 指令允许流水线根据给定的条件决定是否应该执行阶段。 when 指令必须包含至少一个条件。
270 |
271 | ```
272 | //branch: 当正在构建的分支与模式给定的分支匹配时,执行这个阶段,这只适用于多分支流水线例如:
273 | when { branch 'master' }
274 |
275 |
276 | //environment: 当指定的环境变量是给定的值时,执行这个步骤,例如:
277 | when { environment name: 'DEPLOY_TO', value: 'production' }
278 |
279 | //expression 当指定的Groovy表达式评估为true时,执行这个阶段, 例如:
280 | when { expression { return params.DEBUG_BUILD } }
281 |
282 | //not 当嵌套条件是错误时,执行这个阶段,必须包含一个条件,例如:
283 | when { not { branch 'master' } }
284 |
285 | //allOf 当所有的嵌套条件都正确时,执行这个阶段,必须包含至少一个条件,例如:
286 | when { allOf { branch 'master'; environment name: 'DEPLOY_TO', value: 'production' } }
287 |
288 | //anyOf 当至少有一个嵌套条件为真时,执行这个阶段,必须包含至少一个条件,例如:
289 | when { anyOf { branch 'master'; branch 'staging' } }
290 |
291 |
292 | stage('Example Deploy') {
293 | when {
294 | branch 'production'
295 | environment name: 'DEPLOY_TO', value: 'production'
296 | }
297 | steps {
298 | echo 'Deploying'
299 | }
300 | }
301 | ```
302 |
303 |
304 | ### parallel并行
305 | 声明式流水线的阶段可以在他们内部声明多隔嵌套阶段, 它们将并行执行。 注意,一个阶段必须只有一个 steps 或 parallel的阶段。 嵌套阶段本身不能包含 进一步的 parallel 阶段, 但是其他的阶段的行为与任何其他 stageparallel 的阶段不能包含 agent 或 tools阶段, 因为他们没有相关 steps。
306 |
307 |
308 |
309 | ```
310 | stage('Parallel Stage') {
311 | when {
312 | branch 'master'
313 | }
314 | failFast true
315 | parallel {
316 | stage('Branch A') {
317 | agent {
318 | label "for-branch-a"
319 | }
320 | steps {
321 | echo "On Branch A"
322 | }
323 | }
324 | stage('Branch B') {
325 | agent {
326 | label "for-branch-b"
327 | }
328 | steps {
329 | echo "On Branch B"
330 | }
331 | }
332 | }
333 | }
334 | ```
335 |
336 | failFast true 当其中一个进程失败时,强制所有的 parallel 阶段都被终止。
337 |
338 |
339 |
340 | ### script脚本标签
341 |
342 | 可以通过此标签嵌入脚本式语法。
343 |
344 | ```
345 | stage("Build"){
346 | steps{
347 | script{
348 | println("运行构建")
349 | }
350 | }
351 | }
352 | ```
353 |
354 | ---
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
--------------------------------------------------------------------------------
/pipelinesyntax/chapter02/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter02/images/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter02/images/01-subwaybeijing.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter02/images/01-subwaybeijing.jpg
--------------------------------------------------------------------------------
/pipelinesyntax/chapter02/images/02-blueocean.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter02/images/02-blueocean.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter02/images/03-jenkinslog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter02/images/03-jenkinslog.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter03/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter03/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter03/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Jenkins共享库应用
3 | weight: 25
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本模块主要学习Jenkins共享库的配置,目的是能够让大家编写更加灵活强大的流水线😀
9 | {{% /notice %}}
10 |
11 | ### 目录
12 |
13 | + [概述](#概述)
14 | + [共享库内容](#共享库内容)
15 | + [创建共享库](#创建共享库)
16 | + [使用共享库](#使用共享库)
17 |
18 | ---
19 |
20 |
21 | ### 概述
22 |
23 | 共享库这并不是一个全新的概念,其实具有编程能力的同学应该清楚一些。例如在编程语言Python中,我们可以将Python代码写到一个文件中,当代码数量增加,我们可以将代码打包成模块然后再以import的方式使用此模块中的方法。
24 |
25 | 在Jenkins中使用Groovy语法,共享库中存储的每个文件都是一个groovy的类,每个文件(类)中包含一个或多个方法。每个方法包含groovy语句块。
26 |
27 | 我把共享库代码上传到了github,大家可以参考[demo共享库](https://github.com/zeyangli/jenkinslib)
28 |
29 | ### 共享库内容
30 |
31 | 这是一个demo演示的共享库,大家可以看到仓库的结构与内容。这个仓库中包含了很多类,例如:我将kubernetes中的API方法封装在了kubernetes.groovy文件中,便于后面引用。**在此你只需要知道共享库的结构
32 | ,具体该如何创建共享库后面会讲述😀**
33 |
34 |
35 |
36 | ```
37 | ── docs
38 | │ └── README.mdREADME.md
39 | ├── src
40 | │ └── org
41 | │ └── devops
42 | │ └── tools.groovy
43 | └── vars
44 | ```
45 |
46 | src目录主要存放我们要编写的groovy类,执行流水线时,此目录将添加到class_path中。
47 | vars目录主要存放脚本文件,这些脚本文件在流水线中作为变量公开。
48 | resources目录允许从外部库中使用步骤来加载相关联的非Groovy文件。
49 |
50 |
51 | ### 创建共享库
52 |
53 | 新建文件`src/org/devops/tools.groovy`, 在此我将这个文件定义为扩展工具类,主要放一些扩展方法。
54 |
55 | 例如:在构建日志中查看流水线详细日志会很乱,我们可以在日志中将重点步骤通过不同的颜色高亮显示,便于排错。 我们开始写这样的一个方法`PrintMes()`,包含两个参数,输出内容`value`和内容的颜色`color`。
56 |
57 |
58 | {{% notice info %}}
59 | 注意: 我们需要安装 插件`AnsiColor`,这样才能使用ansiColor()方法,可以在`片段生成器`查看更多的用法。
60 | {{% /notice %}}
61 |
62 | ```
63 | package org.devops
64 |
65 | //格式化输出
66 | def PrintMes(value,color){
67 | colors = ['red' : "\033[40;31m >>>>>>>>>>>${value}<<<<<<<<<<< \033[0m",
68 | 'blue' : "\033[47;34m ${value} \033[0m",
69 | 'green' : "[1;32m>>>>>>>>>>${value}>>>>>>>>>>[m",
70 | 'green1' : "\033[40;32m >>>>>>>>>>>${value}<<<<<<<<<<< \033[0m" ]
71 | ansiColor('xterm') {
72 | println(colors[color])
73 | }
74 | }
75 | ```
76 |
77 | ### 使用共享库
78 |
79 | 我们导航到 系统配置 -> `Global Pipeline Libraries`
80 |
81 | 首先,我们为共享库设置一个名称`jenkinslib`,注意这个名称后续在Jenkinsfile中引用。 再设置一个默认的版本,这里的版本是分支的名称。我默认配置的是`master`版本。
82 | 
83 |
84 | 接下来我们配置共享库的仓库地址,我的仓库在github中,所以这里我填写的是github的方式。(如果你用的是gitlab可以使用gitlab方式或者git方式)。如果仓库是私有的方式,需要在jenkins的凭据中添加一个账号用于下载共享库。
85 | 
86 |
87 |
88 | 好,到此共享库在Jenkins的配置就完成了,接下来测试在Jenkinsfile中引用。
89 |
90 | 在Jenkinsfile中使用`@Library('jenkinslib') _ `来加载共享库,注意后面符号`_`用于加载。
91 | 类的实例化`def tools = new org.devops.tools()`,使用类中的方法`tools.PrintMes("获取代码",'green')`。
92 |
93 |
94 |
95 |
96 | ```Jenkinsfile
97 | #!groovy
98 |
99 | @Library('jenkinslib') _
100 |
101 | def tools = new org.devops.tools()
102 |
103 |
104 |
105 | pipeline {
106 | agent { node { label "master" }}
107 |
108 | stages {
109 | //下载代码
110 | stage("GetCode"){
111 | steps{
112 | timeout(time:5, unit:"MINUTES"){
113 | script{
114 | tools.PrintMes("获取代码",'green')
115 | }
116 | }
117 | }
118 | }
119 | }
120 | }
121 |
122 | ```
123 |
124 |
125 | 接下来在你的Jenkins上面运行一下吧,测试一下是否能够看到带有绿色的文字呢?
126 |
--------------------------------------------------------------------------------
/pipelinesyntax/chapter03/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter03/images/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter03/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter03/images/01.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter03/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter03/images/02.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter03/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter03/images/03.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter04/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter04/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter04/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Groovy基础语法
3 | weight: 30
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本模块主要学习Groovy基础语法,掌握基础语法便于在流水线中数据处理😀
9 | {{% /notice %}}
10 |
11 | ### 目录
12 |
13 | + [简介](#简介)
14 | + [安装](#安装)
15 | + [数据类型](#数据类型)
16 | - [字符串string](#字符串string)
17 | - [列表list](#列表list)
18 | - [映射map](#映射map)
19 | + [条件语句](#条件语句)
20 | - [if语句](#if语句)
21 | - [switch语句](#switch语句)
22 | + [循环语句](#循环语句)
23 | - [for循环语句](#for循环语句)
24 | - [while循环语句](#while循环语句)
25 | + [函数](#函数)
26 |
27 | ---
28 |
29 | ### 简介
30 |
31 | Groovy是一种功能强大,可选类型和动态 语言,支持Java平台。旨在提高开发人员的生产力得益于简洁,熟悉且简单易学的语法。可以与任何Java程序顺利集成,并立即为您的应用程序提供强大的功能,包括脚本编写功能,特定领域语言编写,运行时和编译时元编程以及函数式编程。
32 |
33 |
34 | 
35 |
36 |
37 | ### 安装
38 |
39 | * 下载安装包(先安装JDK)
40 | * 解压安装包 获取安装包bin目录
41 | * 写入/etc/profile文件
42 |
43 | ```
44 | export GROOVY_HOME=xxx
45 | export PATH=$PATH:$GROOVY_HOME/bin
46 |
47 | source /etc/profile
48 | ```
49 |
50 | 
51 |
52 |
53 |
54 |
55 | ### 数据类型
56 |
57 |
58 | #### 字符串string
59 | 字符串表示: 单引号、双引号、三引号
60 |
61 | ```
62 | contains() 是否包含特定内容 返回true false
63 | size() length() 字符串数量大小长度
64 | toString() 转换成string类型
65 | indexOf() 元素的索引
66 | endsWith() 是否指定字符结尾
67 | minus() plus() 去掉、增加字符串
68 | reverse() 反向排序
69 | substring(1,2) 字符串的指定索引开始的子字符串
70 | toUpperCase() toLowerCase() 字符串大小写转换
71 | split() 字符串分割 默认空格分割 返回列表
72 | ```
73 |
74 | #### 列表list
75 |
76 | 列表的表示: [] [1,2,3,4]
77 | ```
78 | + - += -= 元素增加减少
79 | isEmpty() 判断add() << 添加元素
80 | 是否为空
81 | intersect([2,3]) disjoint([1]) 取交集、判断是否有交集
82 | flatten() 合并嵌套的列表
83 | unique() 去重
84 | reverse() sort() 反转 升序
85 | count() 元素个数
86 | join() 将元素按照参数链接
87 | sum() min() max() 求和 最小值 最大值
88 | contains() 包含特定元素
89 | remove(2) removeAll()
90 | each{} 遍历
91 | ```
92 |
93 | #### 映射map
94 |
95 | types = ["maven":"mvn"]
96 |
97 | ```
98 | size() map大小
99 | [’key’] .key get() 获取value
100 | isEmpty() 是否为空
101 | containKey() 是否包含key
102 | containValue() 是否包含指定的value
103 | keySet() 生成key的列表
104 | each{} 遍历map
105 | remove(‘a‘) 删除元素(k-v)
106 |
107 | 练习
108 |
109 | groovy:000> [:]
110 | ===> [:]
111 | groovy:000> [1:2]
112 | ===> [1:2]
113 | groovy:000> [1:2][1]
114 | ===> 2
115 | groovy:000> [1:2,3:4,5:6]
116 | ===> [1:2, 3:4, 5:6]
117 | groovy:000> [1:2,3:4,5:6].keySet()
118 | ===> [1, 3, 5]
119 | groovy:000> [1:2,3:4,5:6].values()
120 | ===> [2, 4, 6]
121 | groovy:000> [1:2,3:4,5:6] + [7:8]
122 | ===> [1:2, 3:4, 5:6, 7:8]
123 | groovy:000> [1:2,3:4,5:6] - [7:8]
124 | ===> [1:2, 3:4, 5:6]
125 | ```
126 |
127 |
128 |
129 | ### 条件语句
130 |
131 | #### if语句
132 | 在Jenkinsfile中可用于条件判断。
133 |
134 | ```
135 | if (表达式) {
136 | //xxxx
137 | } else if(表达式2) {
138 | //xxxxx
139 | } else {
140 | //
141 | }
142 |
143 | 练习
144 | groovy:000> buildType = "maven"
145 | ===> maven
146 | groovy:000> if (buildType == "maven"){
147 | groovy:001> println("This is a maven project!")
148 | groovy:002> } else if (buildType == "gradle"){
149 | groovy:003> println("This is a gradle project!")
150 | groovy:004> } else {
151 | groovy:005> println("Project Type Error!")
152 | groovy:006> }
153 | ```
154 |
155 |
156 | #### switch语句
157 |
158 | ```
159 | switch("${buildType}"){
160 | case ”maven":
161 | //xxxx
162 | break;
163 | case ”ant":
164 | //xxxx
165 | break;
166 | default:
167 | //xxxx
168 | }
169 |
170 | 练习
171 | switch("${buildType}"){
172 | case 'maven':
173 | println("This is a maven project !")
174 | break;
175 | ;;
176 |
177 | case 'gradle':
178 | println("This is a gradle projects!")
179 | break;
180 | ;;
181 |
182 | default:
183 | println("Project Type Error!")
184 | ;;
185 | }
186 |
187 | ```
188 |
189 |
190 | ### 循环语句
191 |
192 | #### for循环语句
193 |
194 | ```
195 | test = [1,2,3]
196 | for ( i in test){
197 | ///xxxxxx
198 | break;
199 | }
200 |
201 | //代码
202 | langs = ['java','python','groovy']
203 |
204 | for ( lang in langs ){
205 | if (lang == "java"){
206 | println("lang error in java")
207 | }else {
208 | println("lang is ${lang}")
209 | }
210 | }
211 | ```
212 |
213 |
214 | #### while循环语句
215 |
216 | ```
217 | while(true){
218 | //xxxx
219 | }
220 | ```
221 |
222 |
223 | ### 函数
224 |
225 | 在共享库中每个类中的方法。
226 | ```
227 | def PrintMes(info){
228 | println(info)
229 | return info
230 | }
231 |
232 | response = PrintMes("DevOps")
233 | println(response)
234 | ```
235 |
236 | ---
237 |
238 |
239 |
--------------------------------------------------------------------------------
/pipelinesyntax/chapter04/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter04/images/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter04/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter04/images/01.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter04/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter04/images/02.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter04/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter04/images/03.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter05/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 流水线开发工具
3 | weight: 35
4 | ---
5 |
6 |
7 | {{% notice tip %}}
8 | 您好,本模块主要了解在流水线中常用的方法😀
9 | {{% /notice %}}
10 |
11 | ### 目录
12 |
13 | + [片段生成器](#片段生成器)
14 | + [声明式语法生成器](#声明式语法生成器)
15 | + [全局变量参考](#全局变量参考)
16 | - [env变量](#env变量)
17 | - [currentbuild变量](#currentbuild变量)
18 | + [常用的方法](#常用的方法)
19 |
20 | ---
21 |
22 |
23 | ### 片段生成器
24 |
25 | 使用片段生成器可以根据个人需要生成方法,有些方法来源于插件,则需要先安装相关的插件才能使用哦。
26 |
27 | 
28 |
29 |
30 | 填写好参数后,点击生成,然后复制粘贴到Jenkinsfile
31 | 
32 |
33 |
34 | ### 声明式语法生成器
35 |
36 | 
37 |
38 |
39 |
40 | ### 全局变量参考
41 | 
42 |
43 |
44 | #### env变量
45 |
46 | ```
47 | BUILD_NUMBER //构建号
48 | BUILD_ID //构建号
49 | BUILD_DISPLAY_NAME //构建显示名称
50 | JOB_NAME //项目名称
51 |
52 | EXECUTOR_NUMBER //执行器数量
53 | NODE_NAME //构建节点名称
54 | WORKSPACE //工作目录
55 | JENKINS_HOME //Jenkins home
56 | JENKINS_URL //Jenkins地址
57 | BUILD_URL //构建地址
58 | JOB_URL //项目地址
59 | ```
60 |
61 | #### currentbuild变量
62 |
63 | ```
64 | result currentResult //构建结果
65 | displayName //构建名称 #111
66 | description //构建描述
67 | duration //持续时间
68 | ```
69 |
70 |
71 | ### 常用的方法
72 |
73 | **json数据处理**
74 |
75 | ```
76 | def response = readJSON text: "${scanResult}"
77 | println(scanResult)
78 |
79 | //原生方法
80 | import groovy.json.*
81 |
82 | @NonCPS
83 | def GetJson(text){
84 | def prettyJson = JsonOutput.prettyPrint(text)
85 | new JsonSlurperClassic().parseText(prettyJson)
86 | }
87 |
88 | ```
89 |
90 |
91 | **使用凭据**
92 |
93 | ```
94 | withCredentials([string(credentialsId: "xxxxx", variable: "sonarToken")]) {
95 | println(sonarToken)
96 | }
97 | ```
98 |
99 | 下载代码
100 |
101 | ```
102 | //Git
103 | checkout([$class: 'GitSCM', branches: [[name: "brnachName"]],
104 | doGenerateSubmoduleConfigurations: false,
105 | extensions: [], submoduleCfg: [],
106 | userRemoteConfigs: [[credentialsId: "${credentialsId}",
107 | url: "${srcUrl}"]]])
108 | //Svn
109 | checkout([$class: 'SubversionSCM', additionalCredentials: [],
110 | filterChangelog: false, ignoreDirPropChanges: false,
111 | locations: [[credentialsId: "${credentialsId}",
112 | depthOption: 'infinity', ignoreExternalsOption: true,
113 | remote: "${svnUrl}"]], workspaceUpdater: [$class: 'CheckoutUpdater']]
114 | )
115 | ```
116 |
117 | 展示报告
118 |
119 | ```
120 | publishHTML([allowMissing: false,
121 | alwaysLinkToLastBuild: false,
122 | keepAll: true,
123 | reportDir: './report/',
124 | reportFiles: "a.html, b.html",
125 | reportName: 'InterfaceTestReport',
126 | reportTitles: 'HTML'])
127 |
128 | ```
129 |
130 |
131 | 交互输入
132 |
133 | ```
134 | def result = input message: '选择xxxxx',
135 | ok: '提交',
136 | parameters: [extendedChoice( description: 'xxxxx',
137 | descriptionPropertyValue: '',
138 | multiSelectDelimiter: ',',
139 | name: 'failePositiveCases',
140 | quoteValue: false,
141 | saveJSONParameterToFile: false,
142 | type: 'PT_CHECKBOX',
143 | value: "1,2,3",
144 | visibleItemCount: 99)]
145 | println(result)
146 | ```
147 |
148 |
149 | 构建用户
150 |
151 | ```
152 | wrap([$class: 'BuildUser']){
153 | echo "full name is $BUILD_USER"
154 | echo "user id is $BUILD_USER_ID"
155 | echo "user email is $BUILD_USER_EMAIL"
156 | }
157 | ```
158 |
159 | 制品上传
160 |
161 | ```
162 | rtUpload (
163 | serverId: "artifactory01",
164 | spec:
165 | """{
166 | "files": [
167 | {
168 | "pattern": "report/a.html",
169 | "target": "${repoName}/a/b/v"
170 | }
171 | ]
172 | }"""
173 | )
174 | ```
175 |
176 |
177 | 发送http请求
178 |
179 | ```
180 | ApiUrl = "http://xxxxxx/api/project_branches/list?project=${projectName}"
181 | Result = httpRequest authentication: 'xxxxxxxxx',
182 | quiet: true,
183 | contentType: 'APPLICATION_JSON' ,
184 | url: "${ApiUrl}"
185 | ```
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 | ---
200 |
201 |
202 |
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/images/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter05/images/.DS_Store
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/images/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter05/images/01.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/images/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter05/images/02.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/images/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter05/images/03.png
--------------------------------------------------------------------------------
/pipelinesyntax/chapter05/images/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/pipelinesyntax/chapter05/images/04.png
--------------------------------------------------------------------------------
/shortcodes/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/.DS_Store
--------------------------------------------------------------------------------
/shortcodes/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | date: 2016-04-09T16:50:16+02:00
3 | weight: 15
4 | ---
5 | title: Shortcodes
6 | pre: "3. "
7 |
8 | Hugo uses Markdown for its simple content format. However, there are a lot of things that Markdown doesn’t support well. You could use pure HTML to expand possibilities.
9 |
10 | But this happens to be a bad idea. Everyone uses Markdown because it's pure and simple to read even non-rendered. You should avoid HTML to keep it as simple as possible.
11 |
12 | To avoid this limitations, Hugo created [shortcodes](https://gohugo.io/extras/shortcodes/). A shortcode is a simple snippet inside a page.
13 |
14 | **Hugo-theme-learn** provides multiple shortcodes on top of existing ones.
15 |
16 | {{%children style="h2" description="true" %}}
17 |
--------------------------------------------------------------------------------
/shortcodes/_index.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | date: 2016-04-09T16:50:16+02:00
3 | title: Shortcodes
4 | pre: "3. "
5 | weight: 15
6 | ---
7 |
8 | Hugo utilise Markdown pour son format simple. Cependant, il y a beaucoup de chose que Markdown ne supporte pas bien. On pourrait utiliser du HTML pur pour améliorer les capacité du Markdown.
9 |
10 | Mais c'est probablement une mauvaise idée. Tout le monde utilise le Markdown parce que c'est pur et simple à lire même lorsqu'il est affiché en texte brut. Vous devez éviter le HTML autant que possible pour garder le contenu simple.
11 |
12 | Cependant, pour éviter les limitations, Hugo a créé les [shortcodes](https://gohugo.io/extras/shortcodes/). Un shortcode est un bout de code (*snippet*) dans une page.
13 |
14 | **Hugo-theme-learn** fournit de multiple shortcodes en plus de ceux existant.
15 |
16 | {{%children style="h2" description="true" %}}
17 |
--------------------------------------------------------------------------------
/shortcodes/attachments.en.files/BachGavotteShort.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.en.files/BachGavotteShort.mp3
--------------------------------------------------------------------------------
/shortcodes/attachments.en.files/Carroll_AliceAuPaysDesMerveilles.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.en.files/Carroll_AliceAuPaysDesMerveilles.pdf
--------------------------------------------------------------------------------
/shortcodes/attachments.en.files/adivorciarsetoca00cape.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.en.files/adivorciarsetoca00cape.pdf
--------------------------------------------------------------------------------
/shortcodes/attachments.en.files/hugo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.en.files/hugo.png
--------------------------------------------------------------------------------
/shortcodes/attachments.en.files/movieselectricsheep-flock-244-32500-2.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.en.files/movieselectricsheep-flock-244-32500-2.mp4
--------------------------------------------------------------------------------
/shortcodes/attachments.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Attachments
3 | description : "The Attachments shortcode displays a list of files attached to a page."
4 | ---
5 |
6 | The Attachments shortcode displays a list of files attached to a page.
7 |
8 | {{% attachments /%}}
9 |
10 | ## Usage
11 |
12 | The shortcurt lists files found in a **specific folder**.
13 | Currently, it support two implementations for pages
14 |
15 | 1. If your page is a markdown file, attachements must be place in a **folder** named like your page and ending with **.files**.
16 |
17 | > * content
18 | > * _index.md
19 | > * page.files
20 | > * attachment.pdf
21 | > * page.md
22 |
23 | 2. If your page is a **folder**, attachements must be place in a nested **'files'** folder.
24 |
25 | > * content
26 | > * _index.md
27 | > * page
28 | > * index.md
29 | > * files
30 | > * attachment.pdf
31 |
32 | Be aware that if you use a multilingual website, you will need to have as many folders as languages.
33 |
34 | That's all !
35 |
36 | ### Parameters
37 |
38 | | Parameter | Default | Description |
39 | |:--|:--|:--|
40 | | title | "Attachments" | List's title |
41 | | style | "" | Choose between "orange", "grey", "blue" and "green" for nice style |
42 | | pattern | ".*" | A regular expressions, used to filter the attachments by file name.
The **pattern** parameter value must be [regular expressions](https://en.wikipedia.org/wiki/Regular_expression).
43 |
44 | For example:
45 |
46 | * To match a file suffix of 'jpg', use **.*jpg** (not *.jpg).
47 | * To match file names ending in 'jpg' or 'png', use **.*(jpg|png)**
48 |
49 | ### Examples
50 |
51 | #### List of attachments ending in pdf or mp4
52 |
53 |
54 | {{%/*attachments title="Related files" pattern=".*(pdf|mp4)"/*/%}}
55 |
56 | renders as
57 |
58 | {{%attachments title="Related files" pattern=".*(pdf|mp4)"/%}}
59 |
60 | #### Colored styled box
61 |
62 | {{%/*attachments style="orange" /*/%}}
63 |
64 | renders as
65 |
66 | {{% attachments style="orange" /%}}
67 |
68 |
69 | {{%/*attachments style="grey" /*/%}}
70 |
71 | renders as
72 |
73 | {{% attachments style="grey" /%}}
74 |
75 | {{%/*attachments style="blue" /*/%}}
76 |
77 | renders as
78 |
79 | {{% attachments style="blue" /%}}
80 |
81 | {{%/*attachments style="green" /*/%}}
82 |
83 | renders as
84 |
85 | {{% attachments style="green" /%}}
--------------------------------------------------------------------------------
/shortcodes/attachments.fr.files/BachGavotteShort.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.fr.files/BachGavotteShort.mp3
--------------------------------------------------------------------------------
/shortcodes/attachments.fr.files/Carroll_AliceAuPaysDesMerveilles.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.fr.files/Carroll_AliceAuPaysDesMerveilles.pdf
--------------------------------------------------------------------------------
/shortcodes/attachments.fr.files/adivorciarsetoca00cape.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.fr.files/adivorciarsetoca00cape.pdf
--------------------------------------------------------------------------------
/shortcodes/attachments.fr.files/hugo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.fr.files/hugo.png
--------------------------------------------------------------------------------
/shortcodes/attachments.fr.files/movieselectricsheep-flock-244-32500-2.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zeyangli/jenkins_pipeline_docs/fb73bf7c00a6d196a025e801732fb8501593c047/shortcodes/attachments.fr.files/movieselectricsheep-flock-244-32500-2.mp4
--------------------------------------------------------------------------------
/shortcodes/attachments.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Attachments (Pièces jointes)
3 | description : "The Attachments shortcode displays a list of files attached to a page."
4 | ---
5 |
6 | Le shortcode *Attachments* affiche une liste de pièces jointes d'une page.
7 |
8 | {{% attachments /%}}
9 |
10 | ## Utilisation
11 |
12 | Le shortcode affiche la liste de fichiers trouvés dans un **dossier spécifique**
13 | A l'heure actuelle, il supporte deux implémentations
14 |
15 | 1. Si votre page est un fichier Markdown, les pièces jointes doivent être placée dans un **dossier** nommé comme le nom de la page et suffixé par **.files**.
16 |
17 | > * content
18 | > * _index.md
19 | > * page.files
20 | > * attachment.pdf
21 | > * page.md
22 |
23 | 2. Si votre page est un **dossier**, les pièces jointes doivent être placées dans un dossier fils **'files'**.
24 |
25 | > * content
26 | > * _index.md
27 | > * page
28 | > * index.md
29 | > * files
30 | > * attachment.pdf
31 |
32 | Attention, si votre site est multi-langue, vous devrez avec autant de dossier qu'il y a de langues.
33 |
34 | C'est tout !
35 |
36 | ### Paramètres
37 |
38 | | Paramètre | Défaut | Description |
39 | |:--|:--|:--|
40 | | title | "Pièces jointes" | Titre de la liste |
41 | | style | "" | Choisir entre "orange", "grey", "blue" et "green" pour un style plus sympa |
42 | | pattern | ".*" | Une expression régulière, utilisée pour filtrer les pièces jointes par leur nom de fichier.
Le paramètre **pattern** doit être une [expression régulière](https://en.wikipedia.org/wiki/Regular_expression).
43 |
44 | Par exemple:
45 |
46 | * Pour trouver les fichiers avec le suffixe 'jpg', utilisez **.*jpg** (pas *.jpg).
47 | * Pour trouver les fichiers avec les suffixe 'jpg' ou 'png', utilisez **.*(jpg|png)**
48 |
49 | ### Exemples
50 |
51 | #### Lister les pièces jointes de type pdf ou mp4
52 |
53 |
54 | {{%/*attachments title="Fichiers associés" pattern=".*(pdf|mp4)"/*/%}}
55 |
56 | s'affiche comme
57 |
58 | {{%attachments title="Fichiers associés" pattern=".*(pdf|mp4)"/%}}
59 |
60 | #### Modifier le style
61 |
62 | {{%/*attachments style="orange" /*/%}}
63 |
64 | s'affiche comme
65 |
66 | {{% attachments style="orange" /%}}
67 |
68 |
69 | {{%/*attachments style="grey" /*/%}}
70 |
71 | s'affiche comme
72 |
73 | {{% attachments style="grey" /%}}
74 |
75 | {{%/*attachments style="blue" /*/%}}
76 |
77 | s'affiche comme
78 |
79 | {{% attachments style="blue" /%}}
80 |
81 | {{%/*attachments style="green" /*/%}}
82 |
83 | s'affiche comme
84 |
85 | {{% attachments style="green" /%}}
--------------------------------------------------------------------------------
/shortcodes/button.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Button
3 | description : "Nice buttons on your page."
4 | ---
5 |
6 | A button is a just a clickable button with optional icon.
7 |
8 | ```
9 | {{%/* button href="https://getgrav.org/" */%}}Get Grav{{%/* /button */%}}
10 | {{%/* button href="https://getgrav.org/" icon="fas fa-download" */%}}Get Grav with icon{{%/* /button */%}}
11 | {{%/* button href="https://getgrav.org/" icon="fas fa-download" icon-position="right" */%}}Get Grav with icon right{{%/* /button */%}}
12 | ```
13 |
14 | {{% button href="https://getgrav.org/" %}}Get Grav{{% /button %}}
15 | {{% button href="https://getgrav.org/" icon="fas fa-download" %}}Get Grav with icon{{% /button %}}
16 | {{% button href="https://getgrav.org/" icon="fas fa-download" icon-position="right" %}}Get Grav with icon right{{% /button %}}
17 |
--------------------------------------------------------------------------------
/shortcodes/button.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Button (Bouton)
3 | description : "De beaux boutons sur votre page."
4 | ---
5 |
6 | Le shortcode *button* est simplement un bouton cliquable avec une icône optionnelle.
7 |
8 | ```
9 | {{%/* button href="https://getgrav.org/" */%}}Téléchargez Grav{{%/* /button */%}}
10 | {{%/* button href="https://getgrav.org/" icon="fas fa-download" */%}}Téléchargez Grav avec icône{{%/* /button */%}}
11 | {{%/* button href="https://getgrav.org/" icon="fas fa-download" icon-position="right" */%}}Téléchargez Grav avec icône à droite{{%/* /button */%}}
12 | ```
13 |
14 | {{% button href="https://getgrav.org/" %}}Téléchargez Grav{{% /button %}}
15 | {{% button href="https://getgrav.org/" icon="fas fa-download" %}}Téléchargez Grav avec icône{{% /button %}}
16 | {{% button href="https://getgrav.org/" icon="fas fa-download" icon-position="right" %}}Téléchargez Grav avec icône à droite{{% /button %}}
17 |
--------------------------------------------------------------------------------
/shortcodes/children/_index.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title : Children
3 | description : List the child pages of a page
4 | ---
5 |
6 | Use the children shortcode to list the child pages of a page and the further descendants (children's children). By default, the shortcode displays links to the child pages.
7 |
8 | ## Usage
9 |
10 | | Parameter | Default | Description |
11 | |:--|:--|:--|
12 | | page | _current_ | Specify the page name (section name) to display children for |
13 | | style | "li" | Choose the style used to display descendants. It could be any HTML tag name |
14 | | showhidden | "false" | When true, child pages hidden from the menu will be displayed |
15 | | description | "false" | Allows you to include a short text under each page in the list.
when no description exists for the page, children shortcode takes the first 70 words of your content. [read more info about summaries on gohugo.io](https://gohugo.io/content/summaries/) |
16 | | depth | 1 | Enter a number to specify the depth of descendants to display. For example, if the value is 2, the shortcode will display 2 levels of child pages.
**Tips:** set 999 to get all descendants|
17 | | sort | none | Sort Children By
Weight - to sort on menu orderName - to sort alphabetically on menu labelIdentifier - to sort alphabetically on identifier set in frontmatterURL - URL |
18 |
19 | ## Demo
20 |
21 | {{%/* children */%}}
22 |
23 | {{% children %}}
24 |
25 | {{%/* children description="true" */%}}
26 |
27 | {{%children description="true" %}}
28 |
29 | {{%/* children depth="3" showhidden="true" */%}}
30 |
31 | {{% children depth="3" showhidden="true" %}}
32 |
33 | {{%/* children style="h2" depth="3" description="true" */%}}
34 |
35 | {{% children style="h2" depth="3" description="true" %}}
36 |
37 | {{%/* children style="div" depth="999" */%}}
38 |
39 | {{% children style="div" depth="999" %}}
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/shortcodes/children/_index.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title : Children (Pages filles)
3 | description : Liste les pages filles de la page
4 | ---
5 |
6 | Utilisez le shortcode *children* pour lister les pages filles de la page et tous ses déscendants (pages filles de pages filles). Par défaut, le shortcode affiche des liens vers les pages filles.
7 |
8 | ## Utilisation
9 |
10 | | Paramètre | Défaut | Description |
11 | |:--|:--|:--|
12 | | page | _current_ | Spécifie le nom de la page (nom de la section) à afficher |
13 | | style | "li" | Choisi le style à utiliser pour afficher les descendants. Cela peut être n'importe quel balise HTML |
14 | | showhidden | "false" | Quand *true*, pages filles cachées dans le menu seront affichées quand même |
15 | | description | "false" | Permet d'inclure le texte de la description de la page sous chaque entré de la liste.
quand aucune description existe pour la page, le shortcode prend les 70 premiers mots du contenu. [plus d'infos sur gohugo.io](https://gohugo.io/content/summaries/) |
16 | | depth | 1 | Nombre de descendants à afficher. Par exemple, si la valeur est 2, le shortcode va afficher 2 niveaux de pages filels.
**Astuce:** Utilisez 999 pour avoir tous les descendants|
17 | | sort | | Tri les pages filles par
Weight - PoidsName - NomIdentifier - Trier alphabétiquement par identifiant configuré dans le front matterURL - URL |
18 |
19 | ## Démo
20 |
21 | {{%/* children */%}}
22 |
23 | {{% children %}}
24 |
25 | {{%/* children description="true" */%}}
26 |
27 | {{%children description="true" %}}
28 |
29 | {{%/* children depth="3" showhidden="true" */%}}
30 |
31 | {{% children depth="3" showhidden="true" %}}
32 |
33 | {{%/* children style="h2" depth="3" description="true" */%}}
34 |
35 | {{% children style="h2" depth="3" description="true" %}}
36 |
37 | {{%/* children style="div" depth="999" */%}}
38 |
39 | {{% children style="div" depth="999" %}}
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/shortcodes/children/children-1/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1"
3 | description = "This is a demo child page"
4 | +++
5 |
6 | This is a demo child page
--------------------------------------------------------------------------------
/shortcodes/children/children-1/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1"
3 | description = "This is a demo child page"
4 | +++
5 |
6 | This is a demo child page
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/children-1-1-1/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1-1"
3 | description = "This is a demo child page"
4 | +++
5 |
6 | This is a demo child page
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/children-1-1-1/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1-1"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/children-1-1-1/children-1-1-1-1/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1-1-1"
3 | description = "This is a demo child page"
4 | +++
5 |
6 | This is a demo child page
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/children-1-1-1/children-1-1-1-1/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1-1-1"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/children-1-1-1/children-1-1-1-1/children-1-1-1-1-1/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1-1-1-1"
3 | description = "This is a demo child page"
4 | +++
5 |
6 | This is a demo child page
--------------------------------------------------------------------------------
/shortcodes/children/children-1/children-1-1/children-1-1-1/children-1-1-1-1/children-1-1-1-1-1/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 1-1-1-1-1"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/children-2/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 2"
3 | description = ""
4 | +++
5 |
6 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
7 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
8 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
9 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
10 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
11 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
--------------------------------------------------------------------------------
/shortcodes/children/children-2/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 2"
3 | description = ""
4 | +++
5 |
6 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
7 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
8 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
9 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
10 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
11 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
--------------------------------------------------------------------------------
/shortcodes/children/children-2/test3.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page test 3"
3 | description = "This is a page test"
4 | +++
5 |
6 | This is a test 3 demo child page
--------------------------------------------------------------------------------
/shortcodes/children/children-2/test3.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page test 3"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo test 3
--------------------------------------------------------------------------------
/shortcodes/children/children-3/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 3"
3 | description = "This is a demo child page"
4 | +++
5 |
6 | This is a demo child page, not displayed in the menu
--------------------------------------------------------------------------------
/shortcodes/children/children-3/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 3"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/children-4/_index.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 4"
3 | description = "This is a demo child page"
4 | hidden = true
5 | +++
6 |
7 | This is a demo child page, not displayed in the menu
--------------------------------------------------------------------------------
/shortcodes/children/children-4/_index.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page 4"
3 | description = "Ceci est une page test"
4 | hidden = true
5 | +++
6 |
7 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/children/test.en.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page test"
3 | description = "This is a page test"
4 | +++
5 |
6 | This is a test demo child page
--------------------------------------------------------------------------------
/shortcodes/children/test.fr.md:
--------------------------------------------------------------------------------
1 | +++
2 | title = "page test"
3 | description = "Ceci est une page test"
4 | +++
5 |
6 | Ceci est une page de demo
--------------------------------------------------------------------------------
/shortcodes/expand.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title : Expand
3 | description : "Displays an expandable/collapsible section of text on your page"
4 | ---
5 |
6 | The Expand shortcode displays an expandable/collapsible section of text on your page.
7 | Here is an example
8 |
9 | {{%expand%}}
10 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
11 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
12 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
13 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
14 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
15 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
16 | {{%/expand%}}
17 |
18 |
19 | ## Usage
20 |
21 |
22 | this shortcode takes exactly one optional parameter to define the text that appears next to the expand/collapse icon. (default is "Expand me...")
23 |
24 | {{%/*expand "Is this learn theme rocks ?" */%}}Yes !.{{%/* /expand*/%}}
25 |
26 | {{%expand "Is this learn theme rocks ?" %}}Yes !{{% /expand%}}
27 |
28 | # Demo
29 |
30 | {{%/*expand*/%}}
31 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
32 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
33 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
34 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
35 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
36 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
37 | {{%/* /expand*/%}}
38 |
39 |
40 | {{%expand%}}Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
41 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
42 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
43 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
44 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
45 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.{{% /expand%}}
--------------------------------------------------------------------------------
/shortcodes/expand.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title : Expand
3 | description : "Affiche une section de texte qui se plie et se déplie"
4 | ---
5 |
6 | Le shortcode *Expand* affiche une section de texte qui se plie et se déplie.
7 | Ci-dessous un exemple.
8 |
9 | {{%expand%}}
10 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
11 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
12 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
13 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
14 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
15 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
16 | {{%/expand%}}
17 |
18 |
19 | ## Utilisation
20 |
21 |
22 | Ce shortcode prends exactement un paramètre optionel pour définir le texte à côté de l'icone. (valeur par défaut est "Déroulez-moi...")
23 |
24 | {{%/*expand "Est-ce que ce thème envoie du pâté ?" */%}}Oui !.{{%/* /expand*/%}}
25 |
26 | {{%expand "Est-ce que ce thème envoie du pâté ?" %}}Oui !{{% /expand%}}
27 |
28 | # Demo
29 |
30 | {{%/*expand*/%}}
31 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
32 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
33 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
34 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
35 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
36 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
37 | {{%/* /expand*/%}}
38 |
39 |
40 | {{%expand%}}Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
41 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
42 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
43 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
44 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
45 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.{{% /expand%}}
--------------------------------------------------------------------------------
/shortcodes/mermaid.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title : "Mermaid"
3 | description : "Generation of diagram and flowchart from text in a similar manner as markdown"
4 | ---
5 |
6 | [Mermaid](https://mermaidjs.github.io/) is a library helping you to generate diagram and flowcharts from text, in a similar manner as Markdown.
7 |
8 | Just insert your mermaid code in the `mermaid` shortcode and that's it.
9 |
10 | ## Flowchart example
11 |
12 | {{*mermaid align="left"*/>}}
13 | graph LR;
14 | A[Hard edge] -->|Link text| B(Round edge)
15 | B --> C{Decision}
16 | C -->|One| D[Result one]
17 | C -->|Two| E[Result two]
18 | {{* /mermaid */>}}
19 |
20 | renders as
21 |
22 | {{}}
23 | graph LR;
24 | A[Hard edge] -->|Link text| B(Round edge)
25 | B --> C{Decision}
26 | C -->|One| D[Result one]
27 | C -->|Two| E[Result two]
28 | {{< /mermaid >}}
29 |
30 | or you can use this alternative syntax:
31 |
32 |
33 | ```mermaid
34 | graph LR;
35 | A[Hard edge] -->|Link text| B(Round edge)
36 | B --> C{Decision}
37 | C -->|One| D[Result one]
38 | C -->|Two| E[Result two]
39 | ```
40 |
41 |
42 | renders as
43 |
44 | ```mermaid
45 | graph LR;
46 | A[Hard edge] -->|Link text| B(Round edge)
47 | B --> C{Decision}
48 | C -->|One| D[Result one]
49 | C -->|Two| E[Result two]
50 | ```
51 |
52 | ## Sequence example
53 |
54 | {{*mermaid*/>}}
55 | sequenceDiagram
56 | participant Alice
57 | participant Bob
58 | Alice->>John: Hello John, how are you?
59 | loop Healthcheck
60 | John->John: Fight against hypochondria
61 | end
62 | Note right of John: Rational thoughts
prevail...
63 | John-->Alice: Great!
64 | John->Bob: How about you?
65 | Bob-->John: Jolly good!
66 | {{* /mermaid */>}}
67 |
68 | renders as
69 |
70 | {{}}
71 | sequenceDiagram
72 | participant Alice
73 | participant Bob
74 | Alice->>John: Hello John, how are you?
75 | loop Healthcheck
76 | John->John: Fight against hypochondria
77 | end
78 | Note right of John: Rational thoughts
prevail...
79 | John-->Alice: Great!
80 | John->Bob: How about you?
81 | Bob-->John: Jolly good!
82 | {{< /mermaid >}}
83 |
84 | or you can use this alternative syntax:
85 |
86 |
87 | ```mermaid
88 | sequenceDiagram
89 | participant Alice
90 | participant Bob
91 | Alice->>John: Hello John, how are you?
92 | loop Healthcheck
93 | John->John: Fight against hypochondria
94 | end
95 | Note right of John: Rational thoughts
prevail...
96 | John-->Alice: Great!
97 | John->Bob: How about you?
98 | Bob-->John: Jolly good!
99 | ```
100 |
101 |
102 | renders as
103 |
104 | ```mermaid
105 | sequenceDiagram
106 | participant Alice
107 | participant Bob
108 | Alice->>John: Hello John, how are you?
109 | loop Healthcheck
110 | John->John: Fight against hypochondria
111 | end
112 | Note right of John: Rational thoughts
prevail...
113 | John-->Alice: Great!
114 | John->Bob: How about you?
115 | Bob-->John: Jolly good!
116 | ```
117 |
118 | ## GANTT Example
119 |
120 | {{*mermaid*/>}}
121 | gantt
122 | dateFormat YYYY-MM-DD
123 | title Adding GANTT diagram functionality to mermaid
124 | section A section
125 | Completed task :done, des1, 2014-01-06,2014-01-08
126 | Active task :active, des2, 2014-01-09, 3d
127 | Future task : des3, after des2, 5d
128 | Future task2 : des4, after des3, 5d
129 | section Critical tasks
130 | Completed task in the critical line :crit, done, 2014-01-06,24h
131 | Implement parser and jison :crit, done, after des1, 2d
132 | Create tests for parser :crit, active, 3d
133 | Future task in critical line :crit, 5d
134 | Create tests for renderer :2d
135 | Add to mermaid :1d
136 | {{* /mermaid */>}}
137 |
138 |
139 | renders as
140 |
141 | {{}}
142 | gantt
143 | dateFormat YYYY-MM-DD
144 | title Adding GANTT diagram functionality to mermaid
145 | section A section
146 | Completed task :done, des1, 2014-01-06,2014-01-08
147 | Active task :active, des2, 2014-01-09, 3d
148 | Future task : des3, after des2, 5d
149 | Future task2 : des4, after des3, 5d
150 | section Critical tasks
151 | Completed task in the critical line :crit, done, 2014-01-06,24h
152 | Implement parser and jison :crit, done, after des1, 2d
153 | Create tests for parser :crit, active, 3d
154 | Future task in critical line :crit, 5d
155 | Create tests for renderer :2d
156 | Add to mermaid :1d
157 | {{}}
158 |
159 | or you can use this alternative syntax:
160 |
161 |
162 | ```mermaid
163 | gantt
164 | dateFormat YYYY-MM-DD
165 | title Adding GANTT diagram functionality to mermaid
166 | section A section
167 | Completed task :done, des1, 2014-01-06,2014-01-08
168 | Active task :active, des2, 2014-01-09, 3d
169 | Future task : des3, after des2, 5d
170 | Future task2 : des4, after des3, 5d
171 | section Critical tasks
172 | Completed task in the critical line :crit, done, 2014-01-06,24h
173 | Implement parser and jison :crit, done, after des1, 2d
174 | Create tests for parser :crit, active, 3d
175 | Future task in critical line :crit, 5d
176 | Create tests for renderer :2d
177 | Add to mermaid :1d
178 | ```
179 |
180 |
181 | renders as
182 |
183 | ```mermaid
184 | gantt
185 | dateFormat YYYY-MM-DD
186 | title Adding GANTT diagram functionality to mermaid
187 | section A section
188 | Completed task :done, des1, 2014-01-06,2014-01-08
189 | Active task :active, des2, 2014-01-09, 3d
190 | Future task : des3, after des2, 5d
191 | Future task2 : des4, after des3, 5d
192 | section Critical tasks
193 | Completed task in the critical line :crit, done, 2014-01-06,24h
194 | Implement parser and jison :crit, done, after des1, 2d
195 | Create tests for parser :crit, active, 3d
196 | Future task in critical line :crit, 5d
197 | Create tests for renderer :2d
198 | Add to mermaid :1d
199 | ```
200 |
201 | ### Class example
202 |
203 |
204 | ```mermaid
205 | classDiagram
206 | Class01 <|-- AveryLongClass : Cool
207 | Class03 *-- Class04
208 | Class05 o-- Class06
209 | Class07 .. Class08
210 | Class09 --> C2 : Where am i?
211 | Class09 --* C3
212 | Class09 --|> Class07
213 | Class07 : equals()
214 | Class07 : Object[] elementData
215 | Class01 : size()
216 | Class01 : int chimp
217 | Class01 : int gorilla
218 | Class08 <--> C2: Cool label
219 | ```
220 |
221 |
222 | renders as
223 |
224 | ```mermaid
225 | classDiagram
226 | Class01 <|-- AveryLongClass : Cool
227 | Class03 *-- Class04
228 | Class05 o-- Class06
229 | Class07 .. Class08
230 | Class09 --> C2 : Where am i?
231 | Class09 --* C3
232 | Class09 --|> Class07
233 | Class07 : equals()
234 | Class07 : Object[] elementData
235 | Class01 : size()
236 | Class01 : int chimp
237 | Class01 : int gorilla
238 | Class08 <--> C2: Cool label
239 | ```
240 |
241 | ### Git example
242 |
243 |
244 | ```mermaid
245 | gitGraph:
246 | options
247 | {
248 | "nodeSpacing": 150,
249 | "nodeRadius": 10
250 | }
251 | end
252 | commit
253 | branch newbranch
254 | checkout newbranch
255 | commit
256 | commit
257 | checkout master
258 | commit
259 | commit
260 | merge newbranch
261 | ```
262 |
263 |
264 | renders as
265 |
266 | ```mermaid
267 | gitGraph:
268 | options
269 | {
270 | "nodeSpacing": 150,
271 | "nodeRadius": 10
272 | }
273 | end
274 | commit
275 | branch newbranch
276 | checkout newbranch
277 | commit
278 | commit
279 | checkout master
280 | commit
281 | commit
282 | merge newbranch
283 | ```
--------------------------------------------------------------------------------
/shortcodes/mermaid.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title : "Mermaid"
3 | description : "Génération de diagrammes à partir de texte, dans le même style que Markdown"
4 | ---
5 |
6 | [Mermaid](https://mermaidjs.github.io/) est une bibliothèque Javascript qui permet de générer des diagrammes (séquence, état, gantt, etc.) à partir de texte, dans le même style que Markdown.
7 |
8 | Insérer votre code Mermaid dans un shortcode `mermaid` et c'est tout.
9 |
10 | ## Flowchart example
11 | {{*mermaid align="left"*/>}}
12 | graph LR;
13 | A[Bords droits] -->|Lien texte| B(Bords arondis)
14 | B --> C{Décision}
15 | C -->|Un| D[Résultat un]
16 | C -->|Deux| E[Résultat deux]
17 | {{* /mermaid */>}}
18 |
19 | renders as
20 |
21 | {{}}
22 | graph LR;
23 | A[Bords droits] -->|Lien texte| B(Bords arondis)
24 | B --> C{Décision}
25 | C -->|Un| D[Résultat un]
26 | C -->|Deux| E[Résultat deux]
27 | {{< /mermaid >}}
28 |
29 | or you can use this alternative syntax:
30 |
31 |
32 | ```mermaid
33 | graph LR;
34 | A[Bords droits] -->|Lien texte| B(Bords arondis)
35 | B --> C{Décision}
36 | C -->|Un| D[Résultat un]
37 | C -->|Deux| E[Résultat deux]
38 | ```
39 |
40 |
41 | renders as
42 |
43 | ```mermaid
44 | graph LR;
45 | A[Bords droits] -->|Lien texte| B(Bords arondis)
46 | B --> C{Décision}
47 | C -->|Un| D[Résultat un]
48 | C -->|Deux| E[Résultat deux]
49 | ```
50 |
51 | ## Sequence example
52 |
53 | {{*mermaid*/>}}
54 | sequenceDiagram
55 | participant Alice
56 | participant Bob
57 | Alice->>John: Salut John, comment vas-tu?
58 | loop Vérification
59 | John->John: Se bat contre l'hyponcodrie.
60 | end
61 | Note right of John: Les pensées rationnelles
prédominent...
62 | John-->Alice: Super!
63 | John->Bob: Et toi?
64 | Bob-->John: Au top!
65 | {{* /mermaid */>}}
66 |
67 | renders as
68 |
69 | {{}}
70 | sequenceDiagram
71 | participant Alice
72 | participant Bob
73 | Alice->>John: Salut John, comment vas-tu?
74 | loop Vérification
75 | John->John: Se bat contre l'hyponcodrie.
76 | end
77 | Note right of John: Les pensées rationnelles
prédominent...
78 | John-->Alice: Super!
79 | John->Bob: Et toi?
80 | Bob-->John: Au top!
81 | {{< /mermaid >}}
82 |
83 | or you can use this alternative syntax:
84 |
85 |
86 | ```mermaid
87 | sequenceDiagram
88 | participant Alice
89 | participant Bob
90 | Alice->>John: Salut John, comment vas-tu?
91 | loop Vérification
92 | John->John: Se bat contre l'hyponcodrie.
93 | end
94 | Note right of John: Les pensées rationnelles
prédominent...
95 | John-->Alice: Super!
96 | John->Bob: Et toi?
97 | Bob-->John: Au top!
98 | ```
99 |
100 |
101 | renders as
102 |
103 | ```mermaid
104 | sequenceDiagram
105 | participant Alice
106 | participant Bob
107 | Alice->>John: Salut John, comment vas-tu?
108 | loop Vérification
109 | John->John: Se bat contre l'hyponcodrie.
110 | end
111 | Note right of John: Les pensées rationnelles
prédominent...
112 | John-->Alice: Super!
113 | John->Bob: Et toi?
114 | Bob-->John: Au top!
115 | ```
116 |
117 | ## GANTT Example
118 |
119 | {{*mermaid*/>}}
120 | gantt
121 | dateFormat YYYY-MM-DD
122 | title Ajout de la fonctionnalité de GANTT à Mermaid
123 | section Une section
124 | Tâche complétée :done, des1, 2014-01-06,2014-01-08
125 | Tâche en cours :active, des2, 2014-01-09, 3d
126 | Future tâche : des3, after des2, 5d
127 | Future tâche 2 : des4, after des3, 5d
128 | section Tâches critiques
129 | Tâche complétée dans le chemin critique :crit, done, 2014-01-06,24h
130 | Implémenter le parser et jison :crit, done, after des1, 2d
131 | Créer des tests pour le parser :crit, active, 3d
132 | Future tâche dans le chemin critique :crit, 5d
133 | Créer des tests pour le renderer :2d
134 | Ajout à Mermaid :1d
135 | {{* /mermaid */>}}
136 |
137 |
138 | renders as
139 |
140 | {{}}
141 | gantt
142 | dateFormat YYYY-MM-DD
143 | title Ajout de la fonctionnalité de GANTT à Mermaid
144 | section Une section
145 | Tâche complétée :done, des1, 2014-01-06,2014-01-08
146 | Tâche en cours :active, des2, 2014-01-09, 3d
147 | Future tâche : des3, after des2, 5d
148 | Future tâche 2 : des4, after des3, 5d
149 | section Tâches critiques
150 | Tâche complétée dans le chemin critique :crit, done, 2014-01-06,24h
151 | Implémenter le parser et jison :crit, done, after des1, 2d
152 | Créer des tests pour le parser :crit, active, 3d
153 | Future tâche dans le chemin critique :crit, 5d
154 | Créer des tests pour le renderer :2d
155 | Ajout à Mermaid :1d
156 | {{}}
157 |
158 |
159 | or you can use this alternative syntax:
160 |
161 |
162 | ```mermaid
163 | gantt
164 | dateFormat YYYY-MM-DD
165 | title Ajout de la fonctionnalité de GANTT à Mermaid
166 | section Une section
167 | Tâche complétée :done, des1, 2014-01-06,2014-01-08
168 | Tâche en cours :active, des2, 2014-01-09, 3d
169 | Future tâche : des3, after des2, 5d
170 | Future tâche 2 : des4, after des3, 5d
171 | section Tâches critiques
172 | Tâche complétée dans le chemin critique :crit, done, 2014-01-06,24h
173 | Implémenter le parser et jison :crit, done, after des1, 2d
174 | Créer des tests pour le parser :crit, active, 3d
175 | Future tâche dans le chemin critique :crit, 5d
176 | Créer des tests pour le renderer :2d
177 | Ajout à Mermaid :1d
178 | ```
179 |
180 |
181 | renders as
182 |
183 | ```mermaid
184 | gantt
185 | dateFormat YYYY-MM-DD
186 | title Ajout de la fonctionnalité de GANTT à Mermaid
187 | section Une section
188 | Tâche complétée :done, des1, 2014-01-06,2014-01-08
189 | Tâche en cours :active, des2, 2014-01-09, 3d
190 | Future tâche : des3, after des2, 5d
191 | Future tâche 2 : des4, after des3, 5d
192 | section Tâches critiques
193 | Tâche complétée dans le chemin critique :crit, done, 2014-01-06,24h
194 | Implémenter le parser et jison :crit, done, after des1, 2d
195 | Créer des tests pour le parser :crit, active, 3d
196 | Future tâche dans le chemin critique :crit, 5d
197 | Créer des tests pour le renderer :2d
198 | Ajout à Mermaid :1d
199 | ```
200 |
201 | ### Class example
202 |
203 |
204 | ```mermaid
205 | classDiagram
206 | Class01 <|-- AveryLongClass : Cool
207 | Class03 *-- Class04
208 | Class05 o-- Class06
209 | Class07 .. Class08
210 | Class09 --> C2 : Where am i?
211 | Class09 --* C3
212 | Class09 --|> Class07
213 | Class07 : equals()
214 | Class07 : Object[] elementData
215 | Class01 : size()
216 | Class01 : int chimp
217 | Class01 : int gorilla
218 | Class08 <--> C2: Cool label
219 | ```
220 |
221 |
222 | renders as
223 |
224 | ```mermaid
225 | classDiagram
226 | Class01 <|-- AveryLongClass : Cool
227 | Class03 *-- Class04
228 | Class05 o-- Class06
229 | Class07 .. Class08
230 | Class09 --> C2 : Where am i?
231 | Class09 --* C3
232 | Class09 --|> Class07
233 | Class07 : equals()
234 | Class07 : Object[] elementData
235 | Class01 : size()
236 | Class01 : int chimp
237 | Class01 : int gorilla
238 | Class08 <--> C2: Cool label
239 | ```
240 |
241 | ### Git example
242 |
243 |
244 | ```mermaid
245 | gitGraph:
246 | options
247 | {
248 | "nodeSpacing": 150,
249 | "nodeRadius": 10
250 | }
251 | end
252 | commit
253 | branch newbranch
254 | checkout newbranch
255 | commit
256 | commit
257 | checkout master
258 | commit
259 | commit
260 | merge newbranch
261 | ```
262 |
263 |
264 | renders as
265 |
266 | ```mermaid
267 | gitGraph:
268 | options
269 | {
270 | "nodeSpacing": 150,
271 | "nodeRadius": 10
272 | }
273 | end
274 | commit
275 | branch newbranch
276 | checkout newbranch
277 | commit
278 | commit
279 | checkout master
280 | commit
281 | commit
282 | merge newbranch
283 | ```
284 |
--------------------------------------------------------------------------------
/shortcodes/notice.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Notice
3 | description : "Disclaimers to help you structure your page"
4 | ---
5 |
6 | The notice shortcode shows 4 types of disclaimers to help you structure your page.
7 |
8 | ### Note
9 |
10 | ```
11 | {{%/* notice note */%}}
12 | A notice disclaimer
13 | {{%/* /notice */%}}
14 | ```
15 |
16 | renders as
17 |
18 | {{% notice note %}}
19 | A notice disclaimer
20 | {{% /notice %}}
21 |
22 | ### Info
23 |
24 | ```
25 | {{%/* notice info */%}}
26 | An information disclaimer
27 | {{%/* /notice */%}}
28 | ```
29 |
30 | renders as
31 |
32 | {{% notice info %}}
33 | An information disclaimer
34 | {{% /notice %}}
35 |
36 | ### Tip
37 |
38 | ```
39 | {{%/* notice tip */%}}
40 | A tip disclaimer
41 | {{%/* /notice */%}}
42 | ```
43 |
44 | renders as
45 |
46 | {{% notice tip %}}
47 | A tip disclaimer
48 | {{% /notice %}}
49 |
50 | ### Warning
51 |
52 | ```
53 | {{%/* notice warning */%}}
54 | A warning disclaimer
55 | {{%/* /notice */%}}
56 | ```
57 |
58 | renders as
59 |
60 | {{% notice warning %}}
61 | A warning disclaimer
62 | {{% /notice %}}
63 |
--------------------------------------------------------------------------------
/shortcodes/notice.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Notice
3 | description : "Message pour vous aider à structurer votre contenu"
4 | ---
5 |
6 | Le shortcode *Notice* permet d'afficher 4 types de message pour vous aider à structurer votre contenu.
7 |
8 | ### Note
9 |
10 | ```
11 | {{%/* notice note */%}}
12 | Une notice de type *note*
13 | {{%/* /notice */%}}
14 | ```
15 |
16 | s'affiche comme
17 |
18 | {{% notice note %}}
19 | Une notice de type *note*
20 | {{% /notice %}}
21 |
22 | ### Info
23 |
24 | ```
25 | {{%/* notice info */%}}
26 | Une notice de type *info*
27 | {{%/* /notice */%}}
28 | ```
29 |
30 | s'affiche comme
31 |
32 | {{% notice info %}}
33 | Une notice de type *info*
34 | {{% /notice %}}
35 |
36 | ### Tip
37 |
38 | ```
39 | {{%/* notice tip */%}}
40 | Une notice de type *tip*
41 | {{%/* /notice */%}}
42 | ```
43 |
44 | s'affiche comme
45 |
46 | {{% notice tip %}}
47 | Une notice de type *tip*
48 | {{% /notice %}}
49 |
50 | ### Warning
51 |
52 | ```
53 | {{%/* notice warning */%}}
54 | Une notice de type *warning*
55 | {{%/* /notice */%}}
56 | ```
57 |
58 | s'affiche comme
59 |
60 | {{% notice warning %}}
61 | Une notice de type *warning*
62 | {{% /notice %}}
--------------------------------------------------------------------------------
/shortcodes/siteparam.en.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Site param
3 | description : "Get value of site params variables in your page."
4 | ---
5 |
6 | `siteparam` shortcode is used to help you print values of site params.
7 |
8 | For instance, in this current site, the `editURL` variable is used in `config.toml`
9 |
10 | ```toml
11 | [params]
12 | editURL = "https://github.com/matcornic/hugo-theme-learn/edit/master/exampleSite/content/"
13 | ```
14 |
15 | Use the `siteparam` shortcode to display its value.
16 |
17 | ```
18 | `editURL` Value : {{%/* siteparam "editURL" */%}}
19 | ```
20 |
21 | is displayed as
22 |
23 | `editURL` Value : {{% siteparam "editURL" %}}
--------------------------------------------------------------------------------
/shortcodes/siteparam.fr.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Site param
3 | description : "Afficher la valeur d'un paramètre global du site dans votre page"
4 | ---
5 |
6 | Les shortcode `siteparam` est utilisé pour vous aider à afficher des valeurs provenant des paramètres globaux du site.
7 |
8 | Par exemple, dans ce site, le paramètre `editURL` est utilisé dans le fichier `config.toml`
9 |
10 | ```toml
11 | [params]
12 | editURL = "https://github.com/matcornic/hugo-theme-learn/edit/master/exampleSite/content/"
13 | ```
14 |
15 | Utilisez le shortcode `siteparam` pour affichier sa valeur.
16 |
17 | ```
18 | Valeur de `editURL` : {{%/* siteparam "editURL" */%}}
19 | ```
20 |
21 | s'affiche comme
22 |
23 | Valeur de `editURL` : {{% siteparam "editURL" %}}
--------------------------------------------------------------------------------