jenkins - Jenkins错误:标签必须遵循必需的规范

标签 jenkins kubernetes

我正在尝试为Angular代码创建管道作业,以将应用程序部署到k8集群中。下面是管道容器podTemplate的代码,在构建过程中,我得到下一个错误。

def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(
    cloud: 'kubernetes',
    namespace: 'test',
    imagePullSecrets: ['regcred'],
    label: label,
    containers: [
        containerTemplate(name: 'nodejs', image: 'nodejscn/node:latest', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'docker', image: 'nodejscn/node:latest', ttyEnabled: true, command: 'cat'),
        containerTemplate(name: 'kubectl', image: 'k8spoc1/kubctl:latest', ttyEnabled: true, command: 'cat')
    ],
    volumes: [
        hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
        hostPathVolume(hostPath: '/root/.m2/repository', mountPath: '/root/.m2/repository')
    ]
) {

    node(label) {
      def scmInfo = checkout scm
      def image_tag
      def image_name
      sh 'pwd'
      def gitCommit = scmInfo.GIT_COMMIT
      def gitBranch = scmInfo.GIT_BRANCH
      def commitId
      commitId= scmInfo.GIT_COMMIT[0..7]
      image_tag = "${scmInfo.GIT_BRANCH}-${scmInfo.GIT_COMMIT[0..7]}"

      stage('NPM Install') {
           container ('nodejs') {
              withEnv(["NPM_CONFIG_LOGLEVEL=warn"]) {
                sh 'npm install'
            }
           }
      }
   }
}


来自 Jenkins 的错误:
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: Labels must follow required specs - https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set:  Ubuntu-82f3782f-b5aa-4029-9c51-57610153747c
Finished: FAILURE

我需要提及spec文件的Jenkins值吗?

最佳答案

您收到的错误消息:

ERROR: Labels must follow required specs - https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set:  Ubuntu-82f3782f-b5aa-4029-9c51-57610153747c

精确地指出Pod模板可能出什么问题。如您在ERROR消息中提供的link至kubernetes文档中所见,定义Pod时需要遵循某些规则。 labels元素是dictionary / map字段,要求您提供至少一个键值对,因此您不能只在规范中编写label: label

您可以尝试以PodTemplate格式(主要用于 kubernetes )定义yaml,例如this示例:
podTemplate(yaml: """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: busybox
    image: busybox
    command:
    - cat
    tty: true
"""
) {
    node(POD_LABEL) {
      container('busybox') {
        sh "hostname"
      }
    }
}

如您所见here:

label The label of the pod. Can be set to a unique value to avoid conflicts across builds, or omitted and POD_LABEL will be defined inside the step.


label字段可以完全省略,因此首先可以尝试不使用它,并且不会收到任何错误消息。

关于jenkins - Jenkins错误:标签必须遵循必需的规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59326019/

相关文章:

jenkins - 如何在声明性管道中从 archiveArtifact 中排除文件?

selenium - 在 Jenkins HTML Publisher 上播放视频的问题

node.js - npm 不使用缓存

kubernetes - 自定义对象状态未找到 Kubernetes

kubernetes - 使用 terraform 从外部创建的负载均衡器获取 IP

linux - 别名没有任何影响

jenkins - 我在哪里可以找到 Jenkins 服务器上的 "managed files"物理文件?

kubernetes - 有没有办法创建 Kubernetes Secret 子目录?

java - Kubernetes (minikube) pod OOMKilled,节点中明显剩余大量内存

kubernetes - 您可以在 GKE 集群之间共享 pod 和服务 secondary_ip_range 吗?