配置步骤
1、在manage Jenkins选择 Manage nodes and clouds
2、在manage Credentials里配置访问k8s的 user和token
选择username and password
3、选择Configure Clouds, 配置k8s的 apiserver地址, namespace
4、配置podTemplate
这里jenkins会自动注入一个叫jnlp的容器,默认是没有配置资源限制的,如果你想限制jnlp的资源,可以新建一个名字是jnlp podTemplate, 然后再容器里配置资源限制,镜像得写一个和注入的版本一致的。
使用方式
pipeline {
agent {
kubernetes {
cloud 'kubernetes'
}
}
stages {
stage('Checkout') {
steps {
container('node16') {
git branch: 'main', credentialsId: 'gitlab', url: 'ssh://git@gitlab.xxx.com/xxxx/xxx.git'
}
}