Skip to content

Commit 6ffb8be

Browse files
authored
Merge pull request #1294 from merico-dev/feat-jenkins-pipeline-support-offline
fix: add docs for jenkins-pipeline offline options
2 parents 6bdde74 + 6494965 commit 6ffb8be

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# jenkins-pipeline 插件离线配置
2+
3+
## 功能
4+
5+
目前的 `jenkins-pipeline` 插件配置过程中会连接外部网络来安装插件和配置 `pipeline` 的共享库,为了支持在离线环境中使用 `jenkins-pipeline` 来创建和管理 `jenkins` 流水线,我们在 `jenkins-pipeline` 插件中提供了一个选项 `offline` 用于表示需要在离线环境下配置 `jenkins-pipeline`
6+
7+
## 具体实现
8+
9+
### 插件
10+
11+
流水线正常运行需要依赖 `jenkins` 的几个插件。在离线环境中因为无法下载外部环境的插件,需要在 `jenkins` 预先安装好插件或者使用已经有插件的 `jenkins` 镜像,devstream 官方也提供了已预先安装好所有依赖的镜像 `devstreamdev/jenkins:2.361.1-jdk11-dtm-0.1`
12+
13+
依赖的插件如下:
14+
| 插件名 | 作用 | 备注 |
15+
|--------------|----------------|----------------------------|
16+
| dingding-notifications | 用于发送钉钉通知 | 如果需要使用钉钉通知,则需要安装此插件 |
17+
| github-branch-source | jenkins github 插件 | 如果代码仓库使用的是 github,则必须安装此插件 |
18+
| gitlab-plugin | jenkins gitlab 插件 | 如果代码仓库使用的是 gitlab,则必须安装此插件 |
19+
| sonar | sonar sanner 代码扫描插件 | 如果需要使用 sonarqube,则需要安装此插件 |
20+
| kubernetes | jenkins kubernetes 插件 | 用于 jenkins runner, 必须安装此插件 |
21+
| git | jenkins git 插件 | 用于代码的克隆和权限认证, 必须安装此插件 |
22+
| configuration-as-code | jenkins 配置即代码插件 | 用于 devstream 配置 jenkins 的全局配置, 必须安装此插件|
23+
24+
### 共享库
25+
26+
`jenkins` 中 devstream 默认使用共享库来管理 jenkins 流水线的共用代码,在离线环境中因为无法连接共享库,所以 devstream 提供了单独的 `Jenkinfile` 配置。
27+
28+
29+
## app 示例配置
30+
31+
```yaml
32+
apps:
33+
- name: test
34+
spec:
35+
language: java
36+
framework: springboot
37+
repo:
38+
url: gitlab.com/root/test.git
39+
branch: main
40+
repoTemplate:
41+
url: https://github.com/devstream-io/dtm-repo-scaffolding-java-springboot.git
42+
ci:
43+
- type: template
44+
templateName: ci-pipeline
45+
46+
pipelineTemplates:
47+
- name: ci-pipeline
48+
type: jenkins-pipeline
49+
options:
50+
branch: main
51+
jenkins:
52+
url: jenkins.com
53+
user: admin
54+
offline: true # 在此处设置 offline 为 true, 即开启该 jenkins-pipeline 的离线模式
55+
imageRepo:
56+
user: repoUser
57+
```
58+
59+
使用该配置可得到以下输出:
60+
61+
```text
62+
2022-12-02 19:51:52 ℹ [INFO] Apply started.
63+
2022-12-02 19:51:52 ℹ [INFO] Using local backend. State file: devstream-app.state.
64+
2022-12-02 19:51:52 ℹ [INFO] Tool (repo-scaffolding/test) found in config but doesn't exist in the state, will be created.
65+
2022-12-02 19:51:52 ℹ [INFO] Tool (jenkins-pipeline/test) found in config but doesn't exist in the state, will be created.
66+
2022-12-02 19:51:52 ℹ [INFO] Start executing the plan.
67+
2022-12-02 19:51:52 ℹ [INFO] Changes count: 2.
68+
2022-12-02 19:51:52 ℹ [INFO] -------------------- [ Processing progress: 1/2. ] --------------------
69+
2022-12-02 19:51:52 ℹ [INFO] Processing: (repo-scaffolding/test) -> Create ...
70+
2022-12-02 19:51:52 ℹ [INFO] github start to download repoTemplate...
71+
2022-12-02 19:51:57 ✔ [SUCCESS] Tool (repo-scaffolding/test) Create done.
72+
2022-12-02 19:51:57 ℹ [INFO] -------------------- [ Processing progress: 2/2. ] --------------------
73+
2022-12-02 19:51:57 ℹ [INFO] Processing: (jenkins-pipeline/test) -> Create ...
74+
2022-12-02 19:51:58 ℹ [INFO] jenkins plugin imageRepo start config...
75+
2022-12-02 19:51:58 ⚠ [WARN] jenkins gitlab ssh key not config, private repo can't be clone
76+
2022-12-02 19:52:00 ℹ [INFO] jenkins start config casc...
77+
2022-12-02 19:52:07 ✔ [SUCCESS] Tool (jenkins-pipeline/test) Create done.
78+
2022-12-02 19:52:07 ℹ [INFO] -------------------- [ Processing done. ] --------------------
79+
2022-12-02 19:52:07 ✔ [SUCCESS] All plugins applied successfully.
80+
2022-12-02 19:52:07 ✔ [SUCCESS] Apply finished.
81+
```

internal/pkg/show/config/plugins/jenkins-pipeline.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ tools:
1515
# jenkins namespace in k8s cluster
1616
namespace: jenkins
1717
# restart jenkins if true for plugin install
18-
enableRestart: true
18+
enableRestart: false
19+
# if offline is true, jenkins-pipeline will not install jenkins plugins and share library
20+
# it will use a local Jenkinsfile for jenkins-pipeline
21+
offline: false
1922
scm:
2023
# url is the project repo location, this can be http address or git address
2124
url: [email protected]/root/test-exmaple.git

0 commit comments

Comments
 (0)