Search code examples
kubernetesopenshiftkubernetes-secrets

Issue when trying to create secrets in Openshift : must be set with the mounted {} file path inside '/opt/app-root/src/' ###


I am using OpenShift V4 and trying to create a secret called artifactory-credential which contains Username and Password and is of type 'Opaque'.

I am passing the Username and Password to a secret.yaml file as below

metadata:
  name: "${APP_NAME}-secret"
objects:
  - apiVersion: v1
    kind: Secret
    metadata:
      labels:
        app: ${APP_NAME}
      name: artifactory-credential
    type: Opaque
    stringData:
      username: ${ARTIFACTORY_USER}
      password: ${ARTIFACTORY_PASSWORD}
parameters:
  - name: ARTIFACTORY_USER
    description: "artifactory credential user"
    required: true
  - name: ARTIFACTORY_PASSWORD
    description: "artifactory credential password"

And my build.yaml file has this section:

 spec:
      source:
        type: Secret
        binary: {}
        secrets:
          - secret:
              name: artifactory-credential
              destinationDir: /opt/app-root/src

When I run jenkins pipeline script, I get this error :

### ARTIFACTORY_CREDENTIAL must be set with the mounted artifactory-credential file path inside '/opt/app-root/src/' ###

Any idea why this is happening and what can I do to fix it?


Solution

  • Adding the name to stringData as below worked for me

    type: Opaque
        stringData:
          artifactory-credential: |
            username: ${ARTIFACTORY_USER}
            password: ${ARTIFACTORY_PASSWORD}