如何使用Helm Jenkins Values'凭证Xml Secret'

问题描述 投票:1回答:2

我正在尝试使用helm部署Jenkins。我看到一些值是用XML设置的。但是,我不能以与Master.CredentialsXmlSecret字段相同的方式执行此操作。我试过了:

CredentialsXmlSecret: jenkins-credentials

SecretsFilesSecret:
jenkins-credentials: |-
xml from credentials.xml here

但它不起作用。

jenkins kubernetes-helm
2个回答
1
投票

尝试groovy init脚本,你可以像这样添加helm值:

  InitScripts:
    01-passwords: |- 
    import com.cloudbees.plugins.credentials.impl.*;
    import com.cloudbees.plugins.credentials.*;
    import com.cloudbees.plugins.credentials.domains.*;

    String keyfile = "/tmp/key"

    Credentials c = (Credentials) new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,java.util.UUID.randomUUID().toString(), "description", "user", "password")


    def ksm1 = new CertificateCredentialsImpl.FileOnMasterKeyStoreSource(keyfile)
    Credentials ck1 = new CertificateCredentialsImpl(CredentialsScope.GLOBAL,java.util.UUID.randomUUID().toString(), "description", "password", ksm1)

    def ksm2 = new CertificateCredentialsImpl.UploadedKeyStoreSource(keyfile)
    Credentials ck2 = new CertificateCredentialsImpl(CredentialsScope.GLOBAL,java.util.UUID.randomUUID().toString(), "description", "password", ksm2)

    SystemCredentialsProvider.getInstance().getStore().addCredentials(Domain.global(), c)
    SystemCredentialsProvider.getInstance().getStore().addCredentials(Domain.global(), ck1)
    SystemCredentialsProvider.getInstance().getStore().addCredentials(Domain.global(), ck2)

配置中的此脚本,在您的jenkins中创建凭据和设置。


3
投票

最简单的方法是启动一个Jenkins实例,按照我想要的方式配置它,exec进入它(例如,kubectl exec -it {my-jenkins-pod} /bin/bash),cd进入/var/jenkins_home,然后只需获取相应的文件并对其进行base64编码。

在这种情况下,适当的文件是:

/var/jenkins_home/credentials.xml
/var/jenkins_home/secrets/master.key
/var/jenkins_home/secrets/hudson.util.Secret

例如,您可以使用base64 -w 0 credentials.xml来获取任何这些文件的base64编码内容。然后只需将其复制并粘贴到相应的k8s秘密中即可。

你需要创建的第一个k8s秘密是:

apiVersion: v1
kind: Secret
metadata:
  name: jenkins-credentials
data:
  credentials.xml: AAAGHckcdhie==

credentials.xml赋值的是credentials.xml文件内容的base64编码字符串。

你需要创建的其他k8秘密是:

apiVersion: v1
kind: Secret
metadata:
  name: jenkins-secrets-secret
data:
  master.key: AAAdjkdfjicki+
  hudson.util.Secret: AAAidjciud=

然后在你的values.yaml

CredentialsXmlSecret: jenkins-credentials
SecretsFilesSecret: jenkins-secrets-secret
© www.soinside.com 2019 - 2024. All rights reserved.