安装插件

安装 Kubernetes 插件

配置集群信息

Manage Jenkins -> Configure System -> Cloud

配置Pod模板

配置 jenkins slave 容器

配置volume,让pod中容器共享宿主机docker以及可以使用kebuctl命令访问k8s集群

避免权限问题,配置serviceaccount

测试Freestyle project

创建任务

输入刚刚在pod模板填写的标签

构建里面编写shell脚本

保存后 Build Now,查看pod的整个过程

在jenkins控制台查看构建结果

测试Pipeline

下载 Pipeline 插件

创建流水线

编写pipeline

pipeline {
agent {
label 'node1'
}
stages {
stage('hello world') {
steps {
sh "echo 'hello world'"
}
}
stage('docker') {
steps {
sh "docker info"
}
}
stage('kubectl') {
steps {
sh "kubectl get pods"
}
}
}
}

保存后 Build Now,查看结果