Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-62737

Kubernetes secret doesn't show up in Jenkins /credentials/ page

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I have the following secret in Kubernetes cluster:

      ```

      apiVersion: v1
      kind: Secret
      metadata:
          name: mysecret
          namespace: <namespace>
      labels:
          credential.sync.jenkins.openshift.io: 'true'
      type: Opaque
      data:
          username: <username>
          password: <password>

      ```

      I have tried to restart the jenkins pod in my k8s cluster. However, the secret does not show up in the jenkins /credentials/ page.

      According to https://jenkinsci.github.io/kubernetes-credentials-provider-plugin/ I have also tried the following secret label:

      ```

      apiVersion: v1
      kind: Secret
      metadata:
          name: mysecret
          namespace: <namespace>
      labels:
          "jenkins.io/credentials-type": "usernamePassword"
      type: Opaque
      data:
          username: <username>
          password: <password>

      ```

      And accessing it in my jenkins pipeline Jenkinsfile using the following snippet:

      ```

      withCredentials([usernamePassword(credentialsId: 'nexus', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { withCredentials([usernamePassword(credentialsId: 'mysecret', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')])

      {        echo PASSWORD           echo USERNAME }

      ```

      result in the following error:

      `ERROR: Could not find credentials entry with ID 'mysecret'`

        Attachments

          Activity

          Hide
          rensgroothuijsen Rens Groothuijsen added a comment -

          Kok How Teh Using the latest version of the plugin, it seems to work correctly for me. Assuming that your secret was successfully inserted into the cluster, does the plugin report anything in the system logs?

          Show
          rensgroothuijsen Rens Groothuijsen added a comment - Kok How Teh Using the latest version of the plugin, it seems to work correctly for me. Assuming that your secret was successfully inserted into the cluster, does the plugin report anything in the system logs?
          Hide
          hectoralicea64 Hector Alicea added a comment -

          I have the same issue but in the label section I'm not using 

          credential.sync.jenkins.openshift.io: 'true'

          but rather 

          "jenkins.io/credentials-type": "usernamePassword"

          getting my example from here:

          https://jenkinsci.github.io/kubernetes-credentials-provider-plugin/examples/ 

          Here's my yaml code

          apiVersion: v1
          kind: Secret
          metadata:
          # this is the sonar id.
            name: sonar-credential-secret
            namespace: cicd
            labels:
          # so we know what type it is.
              "jenkins.io/credentials-type": "usernamePassword"
            annotations:
          # description - can not be a label as spaces are not allowed
              "jenkins.io/credentials-description" : "sonar username/password credential stored as a secret in Kubernetes"
          type: Opaque
          stringData:
            username: asdf
            password: asdflkasdflkajsdf
          
          Show
          hectoralicea64 Hector Alicea added a comment - I have the same issue but in the label section I'm not using  credential.sync.jenkins.openshift.io: ' true ' but rather  "jenkins.io/credentials-type" : "usernamePassword" getting my example from here: https://jenkinsci.github.io/kubernetes-credentials-provider-plugin/examples/   Here's my yaml code apiVersion: v1 kind: Secret metadata: # this is the sonar id.   name: sonar-credential-secret   namespace: cicd   labels: # so we know what type it is.     "jenkins.io/credentials-type" : "usernamePassword"   annotations: # description - can not be a label as spaces are not allowed     "jenkins.io/credentials-description" : "sonar username/password credential stored as a secret in Kubernetes" type: Opaque stringData:   username: asdf   password: asdflkasdflkajsdf
          Hide
          hectoralicea64 Hector Alicea added a comment - - edited

          Maybe this is because I'm using the wrong plugin.  I'm using: kubernetes-credentials:0.7.0

          But now I see that my example is for the plugin called:  kubernetes-credentials-provider:0.15
           
          Yep, that was my issue.  Was using the wrong plugin.  Must install the 

          kubernetes-credentials-provider

          plugin
           

          Show
          hectoralicea64 Hector Alicea added a comment - - edited Maybe this is because I'm using the wrong plugin.  I'm using: kubernetes-credentials:0.7.0 But now I see that my example is for the plugin called:  kubernetes-credentials-provider:0.15   Yep, that was my issue.  Was using the wrong plugin.  Must install the  kubernetes-credentials-provider plugin  

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            khteh Kok How Teh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: