Although it seems counterintuitive, I would like to execute an always statement when a conditional is met. In my pipeline, my post statement should always destroy my AWS CloudFormation Stack if a variable is set to true. Below is the post statement which is not correct.
post{
always {
when {
expression { DeleteStack == 'true'}
}
stage("Delete All Stacks") {
steps {
script {
withAWS(region:'us-west-2', credentials:'jenkins-deploy') {
def outputs = cfnDelete(
stack:"${CFTBatchStackName}",
pollInterval:1000)
}
withAWS(region:'us-west-2', credentials:'jenkins-deploy') {
def outputs = cfnDelete(
stack:"${CFTVPCStackName}",
pollInterval:1000)
}
withAWS(region:'us-west-2', credentials:'jenkins-deploy') {
def outputs = cfnDelete(
stack:"${CFTSelfDeleteName}",
pollInterval:1000)
}
}
}
}
}
}
Can I achieve this using a declarative pipeline?