Initial commit: Spicy CDK automation framework
Jenkins shared library and CDK constructs for AWS infrastructure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
61
vars/manualApproval.groovy
Normal file
61
vars/manualApproval.groovy
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Manual approval gate for Spicy CDK pipelines
|
||||
*
|
||||
* Usage:
|
||||
* manualApproval(
|
||||
* time: 4,
|
||||
* timeUnit: "HOURS",
|
||||
* message: "Deploy to Production"
|
||||
* ) {
|
||||
* // deployment code
|
||||
* }
|
||||
*/
|
||||
|
||||
def call(Map args, Closure body) {
|
||||
def userInput = null
|
||||
def aborted = false
|
||||
def allowConcurrentBuildsDuringInput = args.containsKey('allowConcurrentBuildsDuringInput') ? args.allowConcurrentBuildsDuringInput : true
|
||||
|
||||
stage("${args.message} - Approval") {
|
||||
if (allowConcurrentBuildsDuringInput) {
|
||||
spicyUtils.setPipelineProperties(args.pipelineProperties, [disableConcurrentBuilds()])
|
||||
}
|
||||
|
||||
try {
|
||||
timeout(time: args.time, unit: args.timeUnit) {
|
||||
input(
|
||||
message: "${args.message}?",
|
||||
parameters: (args.parameters ?: [])
|
||||
)
|
||||
}
|
||||
} catch (err) {
|
||||
try {
|
||||
def user = err.getCauses()[0].getUser()
|
||||
if (user.toString() == 'SYSTEM') {
|
||||
aborted = !args.runCommandsOnTimeout
|
||||
} else {
|
||||
aborted = true
|
||||
}
|
||||
} catch (ugh) {
|
||||
aborted = true
|
||||
}
|
||||
}
|
||||
|
||||
spicyUtils.setPipelineProperties(args.pipelineProperties, null)
|
||||
|
||||
if (aborted) {
|
||||
return -1
|
||||
}
|
||||
|
||||
catchError {
|
||||
if (args.passUserInputToBody) {
|
||||
body(userInput)
|
||||
} else {
|
||||
body()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
|
||||
Reference in New Issue
Block a user