在Jenkins声明式管道中使用imagePullSecrets

时间:2020-09-30 00:24:20

标签: jenkins kubernetes openshift jenkins-plugins jenkins-groovy

这是我用来创建动态广告连播的Jenkinsfile中的代码段

agent {
        kubernetes {
            label "hello-stage"
            cloud "some-cloud"
            defaultContainer "jnlp"
            idleMinutes 1
            containerTemplate {
                name 'jnlp'
                image 'some-image'
                alwaysPullImage true
                ttyEnabled true
                resourceRequestMemory '1Gi'
                resourceLimitMemory '2Gi' 
            }
            imagePullSecrets '["secret-name"]'
        } // kubernetes
    } // agent

imagePullSecrets之外的所有内容均有效。我试图找到没有运气的文档。我是第一次将Jenkins与Kubernetes结合使用。这是我得到的错误

WorkflowScript: 23: Invalid config option "imagePullSecrets" for agent type "kubernetes". Valid config options are [activeDeadlineSeconds, cloud, containerTemplate, containerTemplates, customWorkspace, defaultContainer, idleMinutes, inheritFrom, instanceCap, label, namespace, nodeSelector, podRetention, serviceAccount, slaveConnectTimeout, supplementalGroups, workingDir, yaml, yamlFile, yamlMergeStrategy] @ line 23, column 13.
            imagePullSecrets '["quay-operator-updates"]'

有人可以帮我弄清楚如何在Jenkins声明性管道中使用imagePullSecrets吗?

谢谢

1 个答案:

答案 0 :(得分:0)

containerTemplate 现在已被弃用,如前所述 here

使用 yaml 语法传递 imagePullSecrets 如下:

pipeline {
    agent {
        kubernetes {
            yaml """\
        apiVersion: v1
        kind: Pod
        metadata:
            name: 'jenkins-slave'
            namespace: 'your-namespace'
        spec:
            containers:
            - name: jnlp
              image: jenkins/inbound-agent:4.3-9-alpine
              tty: true
            - name: demo-application
              image: some-image
              imagePullSecrets:
                  - name: your-secret
              tty: true

        """.stripIndent()
        }
    }
    stages {
        stage('run app') {
            steps {
                container('demo-application') {
                    echo POD_CONTAINER
                }
            }
        }
    }
}