diff --git a/content/en/docs/devops-user-guide/examples/customize-jenkins-agent.md b/content/en/docs/devops-user-guide/examples/customize-jenkins-agent.md new file mode 100644 index 000000000..b1ed79c48 --- /dev/null +++ b/content/en/docs/devops-user-guide/examples/customize-jenkins-agent.md @@ -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. + + {{}} + +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 + ''' + } + } + } + } + } + ``` + + diff --git a/content/zh/docs/devops-user-guide/examples/customize-jenkins-agent.md b/content/zh/docs/devops-user-guide/examples/customize-jenkins-agent.md new file mode 100644 index 000000000..768124056 --- /dev/null +++ b/content/zh/docs/devops-user-guide/examples/customize-jenkins-agent.md @@ -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 文件中的缩进。 + + {{}} + +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 + ''' + } + } + } + } + } + ``` + +