'How to fix Jenkins String Interpolation with downstream job?

I have a parent pipeline job that takes parameters and passes them to a downstream job. I've achieves this in multiple ways with no issue however I keep getting a string interpolation warning that I am trying to fix, but am unable to do so. Based on the documentation (https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation) in most cases using single quotes should work, however this passes the literal name rather than the value (e.g if I set my variable as SECRET_PWD and call it like '${SECRET_PWD}' it shows up as ${SECRET_PWD} on the downstream job instead of the value passed to the parameter.

Here's what I've tried to so far:

Parent Pipeline

pipeline {
  agent any 
  parameters {
  password(defaultValue: "", description: 'The admin password', name: 'SUPER_SECRET_ADMIN_PWD')
  stages {
    stage("Stage1") {
      steps {
        build job: "secret_job/${env.BRANCH}", propagate: true, wait: true, parameters: [
          [$class: 'StringParameterValue', name: 'SUPER_SECRET_ADMIN_PWD',    value: "${params.SUPER_SECRET_ADMIN_PWD}" ]
        ]
      }
    }

This gives the following error in when calling the downstream job.

Warning: A secret was passed to "build" using Groovy String interpolation, which is insecure.
         Affected argument(s) used the following variable(s): [SUPER_SECRET_ADMIN_PWD]
         See https://jenkins.io/redirect/groovy-string-interpolation for details.
The parameter 'SUPER_SECRET_ADMIN_PWD' did not have the type expected by secret_job » secret_branch. Converting to Password Parameter.

Note: I am aware that the StringParameterValue is the reason for the first error. I have changed this in a few different ways to solve that but i still get the interpolation issue.

The other ways I've tried are:

password(name: 'SUPER_SECRET_ADMIN_PWD', value: "${SUPER_SECRET_ADMIN_PWD}") = This works but still interpolation issue
password(name: 'SUPER_SECRET_ADMIN_PWD', value: "${SUPER_SECRET_ADMIN_PWD}") = This does NOT work as it passes ${SUPER_SECRET_ADMIN_PWD} as the value rather than the one entered into the parameter. HOWEVER the interpolation warning goes away
[$class: 'StringParameterValue', name: 'SUPER_SECRET_ADMIN_PWD',    value: '${params.SUPER_SECRET_ADMIN_PWD}' = This does NOT work as it passes ${SUPER_SECRET_ADMIN_PWD} as the value rather than the one entered into the parameter. HOWEVER the interpolation warning goes away

I've also used ${env.SUPER_SECRET_ADMIN_PWD} similar to ${params.SUPER_SECRET_ADMIN_PWD}

Note that I've changed my downstream job to use single quotes and i'm doing a simple sh script something like below with no interpolation errors (I have them before though).

stages{
  stage("test"){
    steps{
     script{
        sh '''
        echo ${SUPER_SECRET_ADMIN_PWD}
        '''
     }
   }
 }

How do I go about solving interpolation and still passing the password parameter down to a downstream job?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source