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

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.

    - name: "maven-jdk11" # The name of the customized Jenkins agent.
      label: "maven jdk11" # The label of the customized Jenkins agent. To specify multiple labels, use spaces to seperate them. 
      inheritFrom: "maven" # The name of the existing pod template from which this customzied Jenkins agent inherits.
      containers:
      - name: "maven" # The container name specified in the existing pod template from which this customzied Jenkins agent inherits.
        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.

    pipeline {
      agent {
        node {
          label 'maven && jdk11'
        }
      }
      stages {
        stage('Print Maven and JDK version') {
          steps {
            container('maven') {
              sh '''
              mvn -v
              java -version
              '''
            }
          }
        }
      }
    }
    

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.

What’s on this Page