forked from bonitasoft/bonita-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
106 lines (85 loc) · 3.86 KB
/
Jenkinsfile
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
@Library('github.com/bonitasoft-presales/[email protected]') _
//def bonitaVersion = "7.14.0"
def bonitaVersionShortened = "7140"
def nodeName = "bcd-${bonitaVersionShortened}"
node("${nodeName}") {
//def scenarioFile = "/home/bonita/bonita-continuous-delivery/scenarios/scenario-ec2.yml"
//def bonitaConfiguration = "Qualification"
// used to archive artifacts
def jobBaseName = "${env.JOB_NAME}".split('/').last()
// used to set build description and bcd_stack_id
def gitRepoName = "${env.JOB_NAME}".split('/')[1]
def normalizedGitRepoName = gitRepoName.toLowerCase().replaceAll('-','_')
// used to set bcd_stack_id
def branchName = env.BRANCH_NAME
def normalizedBranchName = branchName.toLowerCase().replaceAll('-','_')
//bcd_stack_id overrides scenario value
//will deploy all PR on same server
def stackName = "${normalizedGitRepoName}_${normalizedBranchName}_${bonitaVersionShortened}"
// set to true/false if bonitaConfiguration requires a .bconf file
// e.g. configuration has parameters
//def useBConf = false
// set to true/false to switch verbose and debug mode
def debugMode = false
def debug_flag = ''
def verbose_mode= ''
if ("${debugMode}".toBoolean()) {
debug_flag = '-X'
verbose_mode='-v'
}
// used in steps, do not change
def yamlFile = "${WORKSPACE}/props.yaml"
//def bconfFolder = '/home/bonita/bonita-continuous-delivery/bconf'
def yamlStackProps
def privateDnsName
def privateIpAddress
def publicDnsName
def publicIpAddress
def bonitaAwsVersion = '1.0-SNAPSHOT'
def keyFileName = '~/.ssh/presale-ci-eu-west-1.pem'
//def extraVars="${verbose_mode} --extra-vars bcd_stack_id=${stackName} --extra-vars bonita_version=${bonitaVersion}"
ansiColor('xterm') {
timestamps {
stage("Checkout") {
checkout scm
echo "jobBaseName: $jobBaseName"
echo "gitRepoName: $gitRepoName"
}
stage("Create stack") {
sh """
cd ${WORKSPACE}/aws
java -jar bonita-aws-1.3-jar-with-dependencies.jar -c create --stack-id ${stackName} --name ${normalizedGitRepoName} --key-file ${keyFileName}
cp ${stackName}.yaml ${WORKSPACE}
"""
yamlStackProps = readYaml file: "${WORKSPACE}/${stackName}.yaml"
privateDnsName = yamlStackProps.privateDnsName
privateIpAddress = yamlStackProps.privateIpAddress
publicDnsName = yamlStackProps.publicDnsName
publicIpAddress = yamlStackProps.publicIpAddress
echo "privateDnsName: [${privateDnsName}]"
echo "privateIpAddress: [${privateIpAddress}]"
echo "publicDnsName: [${publicDnsName}]"
echo "publicIpAddress: [${publicIpAddress}]"
}
stage("clean SSH known hosts records"){
// ensure private ip/dns name is removed from known hosts since AWS reuse IPs
// keep this stage after build, to ensure SSHd is up & running on created stack
sh """
ssh-keygen -R ${privateDnsName}
ssh-keygen -R ${privateIpAddress}
ssh -o StrictHostKeyChecking=no -i ~/.ssh/presale-ci-eu-west-1.pem ubuntu@${privateDnsName} ls
ssh -o StrictHostKeyChecking=no -i ~/.ssh/presale-ci-eu-west-1.pem ubuntu@${privateIpAddress} ls
"""
}
stage("Deploy docker containers ") {
sh """
cp ${WORKSPACE}/${stackName}.yaml ${WORKSPACE}/ansible/vars/aws_var.yaml
cd ${WORKSPACE}/ansible
ansible-playbook ${WORKSPACE}/ansible/ansible_scenario.yaml -i ${WORKSPACE}/aws/private-inventory-${stackName}.yaml
"""
def bonitaUrl = "http://${publicDnsName}:8084"
currentBuild.description = "<a href='${bonitaUrl}'>${stackName}</a>"
}
} // timestamps
} // ansiColor
} // node