I've spent hours trying different solutions for the same problem as you've had and here is the final solution, which worked for me:
In your pipeline script:
stages { stage("Do something with credentials and pass them to the downstream job") { steps { build job: 'your/jobname/path', parameters: [ [$class: 'hudson.model.PasswordParameterValue', name: 'PASSWORD', value: env.PASSWORD], [$class: 'TextParameterValue', name: 'USERNAME', value: env.USERNAME] ] } }
The trick is to use hudson.model.PasswordParameterValue class when passing password parameter to downstream (Freestyle) job, but you must use then the same class for parameter definition in your main pipeline (parent job) in order to make it work.
For example in your pipeline job you would configure password parameter:
configure { it / 'properties' / 'hudson.model.ParametersDefinitionProperty' / 'parameterDefinitions' << 'hudson.model.PasswordParameterDefinition' { name('PASSWORD') description('My password') } }