Choose Jenkins Agent
The agent section specifies where the entire pipeline or a specific stage will be executed in the Jenkins environment, depending on where the agent
section is placed. This section must be defined at the top level inside the pipeline block, but stage-level usage is optional. For more information, see Jenkins Documentation.
Built-in podTemplate
podTemplate is a Pod template used to create Agents. You can define podTemplates to be used in the Kubernetes plugin.
During the pipeline run, each Jenkins Agent Pod must have a container named jnlp to facilitate communication between the Jenkins Controller and the Jenkins Agent. Additionally, you can add containers in the podTemplate to meet personalized needs. You can use a custom Pod YAML to flexibly control the runtime environment and switch containers using the container command. The following is an example.
pipeline {
agent {
kubernetes {
//cloud 'kubernetes'
label 'mypod'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.3.9-jdk-8-alpine
command: ['cat']
tty: true
"""
}
}
stages {
stage('Run maven') {
steps {
container('maven') {
sh 'mvn -version'
}
}
}
}
}
In the current version, KubeSphere comes with 4 types of podTemplates: base, nodejs, maven, and go, and provides an isolated Docker environment in the Pod.
You can use the built-in podTemplate by specifying the label of the Agent. For example, to use the nodejs podTemplate, specify the label as nodejs when creating the pipeline, as shown in the following example.
pipeline {
agent {
node {
label 'nodejs'
}
}
stages {
stage('nodejs hello') {
steps {
container('nodejs') {
sh 'yarn -v'
sh 'node -v'
sh 'docker version'
sh 'docker images'
}
}
}
}
}
podTemplate base
Name Type/Version Jenkins Agent Label
base
Container Name
base
Operating System
centos-7
Docker
18.06.0
Helm
2.11.0
Kubectl
Stable version
Built-in Tools
unzip, which, make, wget, zip, bzip2, git
podTemplate nodejs
Name Type/Version Jenkins Agent Label
nodejs
Container Name
nodejs
Operating System
centos-7
Node
9.11.2
Yarn
1.3.2
Docker
18.06.0
Helm
2.11.0
Kubectl
Stable version
Built-in Tools
unzip, which, make, wget, zip, bzip2, git
podTemplate maven
Name Type/Version Jenkins Agent Label
maven
Container Name
maven
Operating System
centos-7
Jdk
openjdk-1.8.0
Maven
3.5.3
Docker
18.06.0
Helm
2.11.0
Kubectl
Stable version
Built-in Tools
unzip, which, make, wget, zip, bzip2, git
podTemplate go
Name Type/Version Jenkins Agent Label
go
Container Name
go
Operating System
centos-7
Go
1.11
GOPATH
/home/jenkins/go
GOROOT
/usr/local/go
Docker
18.06.0
Helm
2.11.0
Kubectl
Stable version
Built-in Tools
unzip, which, make, wget, zip, bzip2, git
Feedback
Was this page Helpful?
Receive the latest news, articles and updates from KubeSphere
Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.