Adding certificate to Jenkins configuation as code

2/21/2020

I am configuring an installation of Jenkins through JCasC. One of the plugins we're using is Kubernetes. In order to configure, it needs a server certificate to communicate with the k8s cluster.

This is how that part of the config looks like:

jenkins:
    clouds:
       -kubernetes: 
            name: "kubernetes"
            serverUrl: "k8s URL"
            serverCertificate: "serverCertificate"
            skipTlsVerify: true

I am wondering how I can reference a file that contains the server certificate and put that file at the serverCertificate.

-- Passero
jcasc
jenkins
kubernetes

1 Answer

2/21/2020

I would recommend you to rather use a predefined [jenkins] credentials:

enter image description here

and reference them inside JCasC pipeline as a way of accessing Kubernetes cluster.

jenkins:
  clouds:
    - kubernetes:
        name: "advanced-k8s-config"
        serverUrl: "https://avanced-k8s-config:443"
        skipTlsVerify: true
        namespace: "default"
        credentialsId: "advanced-k8s-credentials"
        jenkinsUrl: "http://jenkins/"
        ...
credentials:
  system:
    domainCredentials:
      - credentials:
          - fileSystemServiceAccountCredential:
              id: "advanced-k8s-credentials"

Please check here for full code example.

-- Nepomucen
Source: StackOverflow