< img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=3131724&fmt=gif" />

Choose Jenkins Agent

The agent section specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed. The section must be defined at the upper-level inside the pipeline block, but stage-level usage is optional. For more information, see the official documentation of Jenkins.

Built-in podTemplate

A podTemplate is a template of a Pod that is used to create agents. Users can define a podTemplate to use in the Kubernetes plugin.

As a pipeline runs, every Jenkins agent Pod must have a container named jnlp for communications between the Jenkins controller and Jenkins agent. In addition, users can add containers in the podTemplate to meet their own needs. They can choose to use their own Pod YAML to flexibly control the runtime, and the container can be switched by the container command. Here 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'
        }
      }
    }
  }
}

At the same time, KubeSphere has some built-in podTemplates, so that users can avoid writing YAML files, greatly reducing learning costs.

In the current version, there are 4 types of built-in podTemplates, i.e. base, nodejs, maven and go. KubeSphere also provides an isolated Docker environment in Pods.

You can use the built-in podTemplate by specifying the label for an agent. For example, to use the nodejs podTemplate, you can set the label to nodejs when creating the Pipeline, as shown in the example below.

jenkins-agent

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

NameType / Version
Jenkins Agent Labelbase
Container Namebase
OScentos-7
Docker18.06.0
Helm2.11.0
KubectlStable release
Built-in toolsunzip, which, make, wget, zip, bzip2, git

podTemplate nodejs

NameType / Version
Jenkins Agent Labelnodejs
Container Namenodejs
OScentos-7
Node9.11.2
Yarn1.3.2
Docker18.06.0
Helm2.11.0
KubectlStable release
Built-in toolsunzip, which, make, wget, zip, bzip2, git

podTemplate maven

NameType / Version
Jenkins Agent Labelmaven
Container Namemaven
OScentos-7
Jdkopenjdk-1.8.0
Maven3.5.3
Docker18.06.0
Helm2.11.0
KubectlStable release
Built-in toolsunzip, which, make, wget, zip, bzip2, git

podTemplate go

NameType / Version
Jenkins Agent Labelgo
Container Namego
OScentos-7
Go1.11
GOPATH/home/jenkins/go
GOROOT/usr/local/go
Docker18.06.0
Helm2.11.0
KubectlStable release
Built-in toolsunzip, which, make, wget, zip, bzip2, git

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.