Jenkins Kubernetes(JCASC)如何将默认容器设置为我的容器而不是JNLP?

huangapple go评论51阅读模式
英文:

Jenkins Kubernetes (JCASC) How to set default container to my container instead of JNLP?

问题

我在Jenkins中使用管道,使用JNLP容器而不是我的容器。

我使用Jenkins作为代码(Jenkins Helm图表)。

如果我将此代码块添加到管道 -

 container('我的容器') {
}

它会使用 '我的容器'。

我如何将其设置为所有我的管道的默认值?我真的需要一直添加这个容器块吗?

英文:

I'm using pipelines in Jenkins that are running using JNLP container instead of my container.

I'm using Jenkins as a code (Jenkin Helm chart)

If I add this block to the pipeline -

 container('my container') {
}

It is using 'my container'.

How do I set it as default to all my pipelines? Do I really need to add this container block all the time?

答案1

得分: 1

根据kubernetes插件文档中提到的信息,您可以使用以下代码全局更改它:

pipeline {
  agent {
    kubernetes {
      defaultContainer 'maven'
      yamlFile 'KubernetesPod.yaml'
    }
  }

  stages {
    stage('Run maven') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}
英文:

As mentioned in kubernetes plugin doc you can change it globally with following code:

pipeline {
  agent {
    kubernetes {
      defaultContainer 'maven'
      yamlFile 'KubernetesPod.yaml'
    }
  }

  stages {
    stage('Run maven') {
      steps {
        sh 'mvn -version'
      }
    }
  }
}

答案2

得分: 0

按照此问题来定义一个不同的默认jnlp容器,请按以下步骤操作:

  1. 转到配置云页面 -> Kubernetes -> 点击Kubernetes云详细信息... -> 点击高级 -> 默认提供程序模板名称。

  2. 在Pod模板中使用相同的名称 -> 名称字段。

  3. 然后设置所需的jnlp容器模板镜像。

附上另一篇博客供您参考。

英文:

As per this issue to define a different default jnlp container follow below steps:

  1. Go to Configure clouds page -> Kubernetes -> Click on Kubernetes
    Cloud details ... -> Click Advanced -> Default Provider Template
    Name.

  2. Use the same name in the Pod Template -> name field.

  3. Then set the desired jnlp container template image.

Attaching another blog for your reference.

huangapple
  • 本文由 发表于 2023年5月17日 14:08:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定