Customize Jenkins Agent

If you need to use a Jenkins agent that runs on a specific environment, for example, JDK 11, you can customize a Jenkins agent on KubeSphere.

This document describes how to customize a Jenkins agent on KubeSphere.

Prerequisites

Customize a Jenkins agent

  1. Log in to the web console of KubeSphere as admin.

  2. Click Platform in the upper-left corner, select Cluster Management, and click Configmaps under Configuration on the left navigation pane.

  3. On the Configmaps page, enter jenkins-casc-config in the search box and press Enter.

  4. Click jenkins-casc-config to go to its details page, click More, and select Edit YAML.

  5. In the displayed dialog box, enter the following code under the data.jenkins_user.yaml:jenkins.clouds.kubernetes.templates section and click OK.

    1. - name: "maven-jdk11" # The name of the customized Jenkins agent.
    2. label: "maven jdk11" # The label of the customized Jenkins agent. To specify multiple labels, use spaces to seperate them.
    3. inheritFrom: "maven" # The name of the existing pod template from which this customzied Jenkins agent inherits.
    4. containers:
    5. - name: "maven" # The container name specified in the existing pod template from which this customzied Jenkins agent inherits.
    6. image: "kubespheredev/builder-maven:v3.2.0jdk11" # This image is used for testing purposes only. You can use your own images.

    Note

    Make sure you follow the indentation in the YAML file.

  6. Wait for at least 70 seconds until your changes are automatically reloaded.

  7. To use the custom Jenkins agent, refer to the following sample Jenkinsfile to specify the label and container name of the custom Jenkins agent accordingly when creating a pipeline.

    1. pipeline {
    2. agent {
    3. node {
    4. label 'maven && jdk11'
    5. }
    6. }
    7. stages {
    8. stage('Print Maven and JDK version') {
    9. steps {
    10. container('maven') {
    11. sh '''
    12. mvn -v
    13. java -version
    14. '''
    15. }
    16. }
    17. }
    18. }
    19. }