jenkins

Ethereal Lv4

1. 打包自己的jenkins

1
2
3
4
5
6
7
8
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/jenkins/jenkins:latest-jdk17
USER root
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN apt-get update && apt-get install -y libltdl7 make
RUN mkdir -p /home/tools/go
COPY go1.22.5.linux-amd64.tar.gz /home/tools/go/
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf /home/tools/go/go1.22.5.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin

2. 上传到阿里云

3. 部署jenkins

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
apiVersion: v1
kind: Service
metadata:
namespace: jenkins
name: service-jenkins
labels:
app: jenkins
spec:
type: NodePort
ports:
- protocol: TCP
port: 80
nodePort: 30080
targetPort: 80
name: jenkins-tcp
- protocol: TCP
port: 10022
nodePort: 30022
targetPort: 10022
name: jenkins-tcp-sshd
selector:
app: jenkins
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: jenkins
name: jenkins-deployment
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
# init block
# init block
nodeName: nodecicd
containers:
- name: jenkins
# k explain pod.spec.containers.imagePullPolicy
# Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always if
# :latest tag is specified, or IfNotPresent otherwise. Cannot be updated. More
# info: https://kubernetes.io/docs/concepts/containers/images#updating-images
image: registry.cn-shanghai.aliyuncs.com/ethereal-o/jenkins:latest
# start init: only run at first deploy
# args: ["init"]
# end init
securityContext:
runAsUser: 0
runAsGroup: 0
env:
- name: 'TZ'
value: 'Asia/Shanghai'
- name: 'JENKINS_OPTS'
value: '--httpPort=80'
- name: 'JENKINS_SLAVE_AGENT_PORT'
value: '10080'
# k explain pod.spec.containers.volumeMounts
# - /external/etc/ssh/ssh_config:/etc/ssh/ssh_config:ro
# - /external/jenkins/var/jenkins_home:/var/jenkins_home
# - /var/run/docker.sock:/var/run/docker.sock
ports:
- containerPort: 80
protocol: TCP
- containerPort: 10080
protocol: TCP
volumeMounts:
- name: jenkins-cfgmap-vol
mountPath: "/etc/ssh/ssh_config"
subPath: "ssh-config"
readOnly: true
- name: jenkins-cfgmap-vol
mountPath: "/etc/apt/sources.list.d/debian.sources"
subPath: "etc-repo"
readOnly: true
# jenkins volume
- name: vol-jenkins-home
mountPath: "/var/jenkins_home"
- name: vol-jenkins-repo
mountPath: "/home/share_data/nginx/share/repo"
- name: vol-docker-socket
mountPath: "/var/run/docker.sock"
- name: vol-docker-exe
mountPath: "/usr/bin/docker"
- name: config-volume
mountPath: /etc/kubernetes/admin.conf # 挂载到容器内的路径
# k explain pod.spec.volumes
volumes:
- name: jenkins-cfgmap-vol
configMap:
# Provide the name of the ConfigMap you want to mount.
name: jenkins-cfgmap
# Must be an octal value between 0000 and 0777
# or a decimal value between 0 and 511.
defaultMode: 0444
# kubectl explain podtemplate.template.spec.volumes.hostPath
- name: vol-jenkins-home
hostPath:
path: "/home/share_data/k8s/jenkins/var/jenkins_home"
type: DirectoryOrCreate
- name: vol-jenkins-repo
hostPath:
path: "/home/share_data/nginx/share/repo"
type: DirectoryOrCreate
- name: vol-docker-socket
hostPath:
path: "/var/run/docker.sock"
type: Socket
- name: vol-docker-exe
hostPath:
path: /usr/bin/docker
- name: config-volume
hostPath:
path: "/etc/kubernetes/admin.conf"
type: File
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: jenkins
name: jenkins-cfgmap
data:
# property-like keys; each key maps to a simple value
ssh-config: |
Host *
IdentityFile /var/jenkins_home/.ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
GSSAPIAuthentication=no

etc-repo: |
Types: deb
# http://snapshot.debian.org/archive/debian/20240311T000000Z
URIs: http://repo.huaweicloud.com/debian
Suites: bookworm bookworm-updates
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
# http://snapshot.debian.org/archive/debian-security/20240311T000000Z
URIs: http://repo.huaweicloud.com/debian-security
Suites: bookworm-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

4. 配置jenkins

需要安装插件Publish Over SSH

5. 配置Gitee的WebHook

参考Jenkins在Linux环境下的安装与配置指南 (baidu.com)

6. 参考

Jenkins在Linux环境下的安装与配置指南 (baidu.com)

Jenkins部署及持续集成——傻瓜式教程-腾讯云开发者社区-腾讯云 (tencent.com)

最详细的k8s中部署Jenkins教程+基于jenkins+k8s(container)实现CI/CD-CSDN博客

docker in docker 出现 libltdl.so.7 问题 - fengjian1585 - 博客园 (cnblogs.com)

运维 - jenkins 手动安装Go 构建环境 - 个人文章 - SegmentFault 思否

  • Title: jenkins
  • Author: Ethereal
  • Created at: 2024-08-01 23:36:22
  • Updated at: 2024-08-01 23:46:33
  • Link: https://ethereal-o.github.io/2024/08/01/jenkins/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments