rsync -uvr --delete --exclude-from $WORKSPACE/CI/exclude-file.txt $WORKSPACE/* $SSHUSERNAME@$SSHSERVER:$REMOTEPATH;
I am not sure if this helps in your branch scenario. I put all my credentials globally then realised I could scope them to the folder level - I missed it due to some nuances in the credentials UI.
Bill
{
"sshUserKey":"sshuserval",
"sshHostKey":"sshhostval"
}
withCredentials([file(credentialsId: 'secrettest', variable: 'testMasterCred')]) {
sh "cat ${testMasterCred}";
}
import groovy.json.JsonSlurperClassic
@NonCPS
def parseJsonToMap(String json) {
final slurper = new JsonSlurperClassic()
return new HashMap<>(slurper.parseText(json))
}
Another way to go would be a command line tool to parse JSON like this one:
https://stedolan.github.io/jq/
Then just run a 'sh' command to get the data out. I haven't used that myself.
Have fun!
--Bill
steps {
echo "Deploying Develop Branch"
withCredentials([file(credentialsId: 'develop_credentials', variable: 'MY_SECRET_FILE')]) {
script {
MY_SECRET_FILE_CONTENT = sh (
script: "cat ${MY_SECRET_FILE}",
returnStdout: true
).trim()
def creds = parseJsonToMap(MY_SECRET_FILE_CONTENT)
echo "Sending files to remote server"
sh "rsync -uvr --delete --exclude-from ${WORKSPACE}/CI/exclude-file.txt ${WORKSPACE}/* ${creds.sshUser}@${creds.sshServer}:${creds.sshRemotePath};"
}
}
}
MY_SECRET_FILE_CONTENT = readFile MY_SECRET_FILE