I am trying to access json file using parameter (tried file, stashed) so that I can read content of file(key, value) and process the content. I am not able to read the file successfully. I have tried multiple ways: some examples are here:
properties([
parameters([
file(name: ‘uploadFile’, description: ‘Upload Secrets JSON file’),
base64File(name: ‘FILE’, description: “File to read”),
stashedFile(name: ‘large’),
)
])
])
pipeline {
agent any
stages {
stage('read multiple key values ') {
steps {
echo “Before Script”
script {
echo “Add Multiple Secrets to Key Vault”
unstash ‘large’
sh(script: ‘cat large’, returnStdout: true)
echo "END UNSTASH"
withFileParameter('FILE') {
sh(script: 'cat $FILE', returnStdout: true)
echo "END withFileParameter"
def jsonFilePath = large
echo "File PAth: ${jsonFilePath}"
def secrets = readJSON file: jsonFilePath
secrets.each { secret ->
if (secret.name && secret.value) {
echo "Adding secret ${secret.name} to Key Vault"
} else {
echo "Secret name or value is missing"
}
}
}
}
}
}
}
}