一、安装 jenkins
helm repo add jenkinsci https://charts.jenkins.io
helm repo update
kubectl create ns jenkins
helm upgrade --install jenkins jenkinsci/jenkins -n jenkins --create-namespace -f values.yaml
# # =================================================================================================
# # 自定义配置
# # =================================================================================================
# # 1. 修改需要安装的插件
# # 这里额外增加了 ws-cleanup 和中文语言包
# controller:
# installPlugins:
# - kubernetes:3937.vd7b_82db_e347b_
# - workflow-aggregator:596.v8c21c963d92d
# - git:5.1.0
# - ws-cleanup:0.45
# - localization-zh-cn:1.0.24
# - configuration-as-code:1647.ve39ca_b_829b_42
# # ---------------------------------------------------------------------------
# # 2. 修改默认密码
# controller:
# adminPassword: "123321"
# # ---------------------------------------------------------------------------
# # 3. 修改执行并发数
# controller:
# numExecutors: 10
# # ---------------------------------------------------------------------------
# # 4. 开启 NodePort 方式访问
# controller:
# serviceType: NodePort
controller:
installPlugins:
- kubernetes:3937.vd7b_82db_e347b_
- workflow-aggregator:596.v8c21c963d92d
- git:5.1.0
- ws-cleanup:0.45
- localization-zh-cn:1.0.24
- configuration-as-code:1647.ve39ca_b_829b_42
adminPassword: "123456"
numExecutors: 10
serviceType: NodePort
https://plugins.jenkins.io/kubernetes/
pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins: worker
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
command: ["/busybox/cat"]
tty: true
volumeMounts:
- name: dockercred
mountPath: /root/.docker/
volumes:
- name: dockercred
secret:
secretName: dockercred
"""
}
}
stages {
stage('Stage 1: Build with Kaniko') {
steps {
container('kaniko') {
sh '/kaniko/executor --context=git://github.com/repository/project.git \
--destination=repository/image:tag \
--insecure \
--skip-tls-verify \
-v=debug'
}
}
}
}
}
example
podTemplate(containers: [
containerTemplate(name: 'maven', image: 'maven:3.8.1-jdk-8', command: 'sleep', args: '99d'),
containerTemplate(name: 'golang', image: 'golang:1.16.5', command: 'sleep', args: '99d')
]) {
node(POD_LABEL) {
stage('Get a Maven project') {
git 'https://github.com/jenkinsci/kubernetes-plugin.git'
container('maven') {
stage('Build a Maven project') {
sh 'echo hello world'
}
}
}
stage('Get a Golang project') {
git url: 'https://github.com/hashicorp/terraform.git', branch: 'main'
container('golang') {
stage('Build a Go project') {
sh '''
mkdir -p /go/src/github.com/hashicorp
ln -s `pwd` /go/src/github.com/hashicorp/terraform
go mod download
cd /go/src/github.com/hashicorp/terraform && make
'''
}
}
}
}
}