声明式Jenkins管道使用现有的Kubernetes Pod模板 [英] Declarative Jenkins Pipeline use existing Kubernetes Pod Template

查看:472
本文介绍了声明式Jenkins管道使用现有的Kubernetes Pod模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在OpenShift集群中使用OpenShift Jenkins图像.默认的Jenkins映像将导致Jenkins容器被预先配置为指向我的Kubernetes集群.此外,该容器还定义了两个Kubernetes Pod模板,一个用于maven,一个用于nodejs.

I am using the OpenShift Jenkins image within an OpenShift Cluster. This default Jenkins image results in a Jenkins container that is preconfigured to point to my Kubernetes cluster. Additionally, the container has two Kubernetes pod templates defined, one for maven and one for nodejs.

我现在想做的是使用声明性管道并引用这些容器.我尝试了以下

What I would now like to do is use a declarative pipeline and reference these pods. I tried the following

  agent {
     kubernetes {
     //cloud 'kubernetes'
     label 'maven'
     }
  }

但这给出了一个错误提示

But that gives an error stating

org.codehaus.groovy.control.MultipleCompilationErrorsException: 启动失败:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

WorkflowScript:4:代理类型缺少必需的参数 "kubernetes":containerTemplate @第4行,第10列.

WorkflowScript: 4: Missing required parameter for agent type "kubernetes": containerTemplate @ line 4, column 10.

        kubernetes {

        ^

所有(

All of the (examples) that I can find for declarative pipelines show the pod templates being defined when the agent is specified.

是否可以在声明管道中重用已经定义的模板?

Is it possible to reuse already defined templates in a declarative pipeline?

推荐答案

以下是使用预定义的pod模板的示例.

Here is an example using a pre-defined pod template.

pipeline {
  agent {
      label "maven"
  }
  stages {
    stage('Run maven') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}

您原来的管道定义实际上是在定义一个全新的pod模板,因此该错误强制执行containerTeamplates参数的要求.使用现有模板时,只需在agent块中指定标签.

Your original pipeline definition was in effect defining a brand new pod template and hence the error enforcing the requirement for containerTeamplates parameter. When using an existing template, you can simply specify the label in the agent block.

这篇关于声明式Jenkins管道使用现有的Kubernetes Pod模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆