/*
* Define how to deploy a project without waiting.
* We assume we are already in a node context.
* Deployment on corresponding environment will be attempted only if the file exist in the '.jenkins/config' directory:
* - dev.groovy
* - tst.groovy
* - stg.groovy
* - prd.groovy
*/
def deploy_now(String targetEnv = 'dev') {
stage ("Deploy to ${targetEnv}") {
go = 'undefined'
try {
// load parameters for the environment ${targetEnv}
load path: ".jenkins/${targetEnv}.groovy"
echo "Variables defined for deployment in .jenkins/${targetEnv}.groovy : " +
"credentialsID=${credentialsId}, " +
"server=${target_server}, " +
"user=${target_user}"
go = 'true'
}
catch (e) {
echo "No deployment done since the environment is not defined in .jenkins/${targetEnv}.groovy"
go = 'false'
}
//echo "${go}"
if ( "${go}"== 'true' ) {
ansiblePlaybook(
credentialsId: "${credentialsId}",
extras: "--user=${target_user} --verbose",
installation: "ansible",
inventory: "${target_server},",
playbook: ".jenkins/deploy.yml",
sudoUser: null
)
}
}
}