Add Docs: Customize Jenkins Agent (#2225)

* Add Docs: Customize Jenkins Agent

Signed-off-by: Felixnoo <felixliu@kubesphere.io>

* resolve comments

Signed-off-by: Felixnoo <felixliu@kubesphere.io>

* minor updates

Signed-off-by: Felixnoo <felixliu@kubesphere.io>
This commit is contained in:
Felixnoo 2021-12-28 10:35:24 +08:00 committed by GitHub
parent 8f8118f148
commit aa459a47d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,70 @@
---
title: "Customize Jenkins Agent"
keywords: "KubeSphere, Kubernetes, DevOps, Jenkins, Agent"
description: "Learn how to customize a Jenkins agent on KubeSphere."
linkTitle: "Customize Jenkins Agent"
Weight: 11460
---
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
- You have enabled [the KubeSphere DevOps System](../../../pluggable-components/devops/).
## 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**.
```yaml
- 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.
```
{{< notice note >}}
Make sure you follow the indentation in the YAML file.
{{</ notice >}}
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.
```groovy
pipeline {
agent {
node {
label 'maven && jdk11'
}
}
stages {
stage('Print Maven and JDK version') {
steps {
container('maven') {
sh '''
mvn -v
java -version
'''
}
}
}
}
}
```

View File

@ -0,0 +1,70 @@
---
title: "自定义 Jenkins Agent"
keywords: "KubeSphere, Kubernetes, DevOps, Jenkins, Agent"
description: "了解如何在 KubeSphere 上自定义 Jenkins Agent。"
linkTitle: "自定义 Jenkins Agent"
Weight: 11460
---
如果您需要使用运行特定环境(例如 JDK 11的 Jenkins Agent您可以在 KubeSphere 上自定义 Jenkins Agent。
本文档描述如何在 KubeSphere 上自定义 Jenkins Agent。
## 准备工作
- 您需要启用 [KubeSphere DevOps 系统](../../../pluggable-components/devops/)。
## 自定义 Jenkins Agent
1. 以 `admin` 用户登录 KubeSphere Web 控制台。
2. 点击左上角的**平台管理**,选择**集群管理**,然后在左侧导航栏点击**配置**下的**配置字典**。
3. 在**配置字典**页面的搜索框中输入 `jenkins-casc-config` 并按**回车键**。
4. 点击 `jenkins-casc-config` 进入其详情页面,点击**更多操作**,选择**编辑 YAML**。
5. 在弹出的对话框中,搜寻至 `data.jenkins_user.yaml:jenkins.clouds.kubernetes.templates` 下方并输入以下代码,点击**确定**。
```yaml
- name: "maven-jdk11" # 自定义 Jenkins Agent 的名称。
label: "maven jdk11" # 自定义 Jenkins Agent 的标签。若要指定多个标签,请用空格来分隔标签。
inheritFrom: "maven" # 该自定义 Jenkins Agent 所继承的现有容器组模板的名称。
containers:
- name: "maven" # 该自定义 Jenkins Agent 所继承的现有容器组模板中指定的容器名称。
image: "kubespheredev/builder-maven:v3.2.0jdk11" # 此镜像只用于测试。您可以使用自己的镜像。
```
{{< notice note >}}
请确保遵守 YAML 文件中的缩进。
{{</ notice >}}
6. 请至少等待 70 秒,您的改动会自动重新加载。
7. 要使用自定义 Jenkins Agent请参考下方的示例 Jenkinsfile在创建流水线时指定自定义 Jenkins Agent 对应的标签和容器名。
```groovy
pipeline {
agent {
node {
label 'maven && jdk11'
}
}
stages {
stage('Print Maven and JDK version') {
steps {
container('maven') {
sh '''
mvn -v
java -version
'''
}
}
}
}
}
```