I have this Jenkins pipeline where I need to run ansiblePlaybook() command with inventory file. Inventory file does contain date (current date) part (my-instance-ips-(mm-dd-yyyy)). Here, I am facing issue in creating currentDate variable and pass into pipeline script
Jenkins File:
pipeline {
agent any
stages {
stage ( 'Executing shell script' ) {
steps {
script {
sh """
currentDate = "\$(date +'%m-%d-%Y')"
inventory_file = "my-instance-ips-{$currentDate}.yml"
ansiblePlaybook (
playbook: 'task.yml',
inventory: $inventory_file,
installation: 'ansible-2.6.5','
-e "DATE = $currentDate")
"""
}
}
}
}
}
Error Message:
groovy.lang.MissingPropertyException: No such property: currentDate for class: groovy.lang.Bindin
Could someone help me out to create current date in pipeline script and the same should pass over to ansible playbook command?