Search code examples
azurejenkinskubernetes-helmazure-aksazure-keyvault

Helm | Jenkins Azure keyvault secrets are passing as masked(********),So it's throwing no value exception in helm command


I'm trying deploy the java microservices into azure kubernetes using helm charts, My application having few secret like DB username and passwords. I stored my secrets in azure keyvault. Using Azure Key vault plugin and service principal I'm trying to fetch the secrets. Test connection was successfully in the plugin and I can able print my secretes as I mentioned below. But while passing the secretes into helm commands i'm getting an following exception

Error: failed parsing --set data: key "****" has no value

If I'm hardcoding the secretes, it's working.

My jenkins file looks like below

    *** Pipeline Code ***
pipeline {
  agent any
  environment {
    DB-USERNAME = credentials('db-username')
    DB-PASSWORD = credentials('db-password')

  }
  stages {
    stage('Foo') {
      steps {
        echo DB-USERNAME
        echo DB-USERNAME.substring(0, DB-USERNAME.size() -1) // shows the right secret was loaded

sh 'helm upgrade --install $SERVICE $CHART_NAME --set $DB-USERNAME --set $DB-PASSWORD

      }
    }
  }
}

Anyone please advise me on this

Reference :

https://linuxhelp4u.blogspot.com/2020/04/integrate-jenkins-with-azure-key-vault.html

https://plugins.jenkins.io/azure-keyvault/


Solution

  • Use double quote sh once

    • if you are using "double quotes", $var in sh "... $var ..." will be interpreted as Jenkins variable;

    • if you are using 'single quotes', $var in sh '... $var ...' will be interpreted as shell variable.

    Example

    pipeline {
      agent any
      environment {
        DB-USERNAME = credentials('db-username')
        DB-PASSWORD = credentials('db-password')
    
      }
      stages {
        stage('Foo') {
          steps {
            echo DB-USERNAME
            echo DB-USERNAME.substring(0, DB-USERNAME.size() -1) // shows the right secret was loaded
    
    sh "helm upgrade --install $SERVICE $CHART_NAME --set $DB-USERNAME --set $DB-PASSWORD"
    
          }
        }
      }
    }