-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.stacks
76 lines (71 loc) · 3.03 KB
/
Jenkinsfile.stacks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def stacksToSelect = ""
def selectedEnv = ""
pipeline {
agent any
environment {
AWS_DEFAULT_REGION = 'eu-west-1' // Change to your region
CDK_STACK_NAME = 'CdpCdkPythonStack' // Change to your stack name
// PYTHONPATH= '/usr/local/lib/python3.12/site-packages:/var/lib/jenkins/.local/lib/python3.12/site-packages'
}
parameters {
booleanParam(name: 'PROCEED_TO_DEPLOY', defaultValue: false, description: 'Select Yes to proceed to deployment after synthesizing.')
choice(name: 'USECASE', choices: ['serverless ns and wg', 'producer datashare', 'consumer datashare', 'cdp delete account'], description: 'Select the usecase')
choice(name: 'ENV', choices: ['int', 'test', 'live'], description: 'Select the environment')
}
stages {
stage('Checkout Code') {
steps {
checkout scm
}
}
stage('Activate env, install dependencies and synthesize') {
steps {
script {
def selectedUsecase = params.USECASE
selectedEnv = params.ENV
// Use Python3.12, activate new venv, install Python dependencies, synthesize the CDK app
def initCommand = "python3.12 -m venv new-venv && source new-venv/bin/activate && python3 --version && pip install -r requirements.txt && python3 --version && cdk synth --context env="
switch (selectedUsecase) {
case "serverless ns and wg":
stacksToSelect = "SecretsManagerStack RedshiftRolePolicyStack"
break
case "producer datashare":
stacksToSelect = "SecretsManagerStack CdpPiiDatashareStack"
break
case "consumer datashare":
stacksToSelect = "SecretsManagerStack ScvConsumerDatashareStack"
break
case "cdp delete account":
stacksToSelect = "CDPDeleteAccountStack"
break
}
command = initCommand + selectedEnv + " " + stacksToSelect
sh command
}
}
}
stage('Confirm Deployment') {
when {
expression {
params.PROCEED_TO_DEPLOY
}
}
steps {
script {
echo "Proceeding to 'cdk deploy' as PROCEED_TO_DEPLOY is true..."
def initCommand = "source new-venv/bin/activate && cdk deploy --require-approval never --context env="
command = initCommand + selectedEnv + " " + stacksToSelect
sh command
}
}
}
}
post {
success {
echo "Pipeline execution completed successfully!"
}
failure {
echo "Pipeline execution failed."
}
}
}