forked from hmcts/ccpay-cpo-function-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile_parameterized
71 lines (63 loc) · 2.32 KB
/
Jenkinsfile_parameterized
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
#!groovy
//noinspection GroovyUnusedAssignment
@Library("Infrastructure") _
//noinspection GroovyAssignabilityCheck
properties([
parameters([
choice(name: 'ENVIRONMENT', choices: 'saat\nsprod\nsandbox', description: 'Environment where code should be build and deployed')
])
])
def product = "ccpay"
def component = "cpo-callback-function"
def environment = params.ENVIRONMENT
def subscription = 'sandbox'
echo "Building '${product}-${component}' in '${environment}'"
List<LinkedHashMap<String, Object>> secrets = [
secret('ccpay-cpo-s2s-secret', 'S2S_KEY_CCPAY_CPO_FUNCTION')
]
static LinkedHashMap<String, Object> secret(String secretName, String envVar) {
[ $class: 'AzureKeyVaultSecret',
secretType: 'Secret',
name: secretName,
version: '',
envVariable: envVar
]
}
node {
env.PATH = "$env.PATH:/usr/local/bin"
stage('Checkout') {
deleteDir()
checkout scm
}
stage('Build') {
yarn("--mutex network install")
}
withParameterizedPipeline(params.TYPE, params.PRODUCT_NAME, params.APP, params.ENVIRONMENT, params.SUBSCRIPTION) {
after('build') {
sh 'yarn ng:build'
}
loadVaultSecrets(secrets)
}
withSubscription(subscription) {
withIlbIp(environment) {
spinInfra(product, component, environment, false, subscription)
scmServiceRegistration(environment)
}
deployStage(product, component, environment, subscription)
}
}
def deployStage(product, component, environment, subscription) {
stage("Deploy Functions") {
def az = { cmd -> return sh(script: "env AZURE_CONFIG_DIR=/opt/jenkins/.azure-$subscription az $cmd", returnStdout: true).trim() }
def serviceName = "${product}-${component}-${environment}"
def result = az "functionapp deployment list-publishing-profiles --name ${serviceName} --resource-group ${serviceName} --query \"[?publishMethod=='MSDeploy'].{publishUrl:publishUrl,userName:userName,userPWD:userPWD}|[0]\""
def profile = readJSON text: result
def uri = "${profile.userName}:${profile.userPWD}@${profile.publishUrl}"
sh "bash uploadSource.sh ${serviceName} functions https://\\${uri}"
}
}
def yarn(task) {
sh "cd functions"
sh("yarn ${task}")
sh "cd .."
}