-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
101 lines (86 loc) · 3.03 KB
/
Jenkinsfile
File metadata and controls
101 lines (86 loc) · 3.03 KB
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
node {
tools {"org.jenkinsci.plugins.terraform.TerraformInstallation" "terraform-0.11.10"}
environment {
TF_HOME = tool('terraform-0.11.10')
TF_IN_AUTOMATION = "true"
PATH = "$TF_HOME:$PATH"
ACCESS_KEY = credentials('jenkins-aws-secret-key-id')
SECRET_KEY = credentials('jenkins-aws-secret-access-key')
}
echo "workspace directory is ${workspace}"
stage('checkout') {
checkout scm
}
stage('check java') {
sh "java -version"
}
script {
version = sh (
script: "./gradlew properties -q | grep \"^version:\" | awk '{print \$2}'",
returnStdout: true
).trim()
sh "echo Building project in version: $version"
}
stage('clean') {
sh "chmod +x gradlew"
sh "./gradlew clean --no-daemon"
}
stage('build') {
sh "./gradlew npm_install -Pprod -PnodeInstall --no-daemon"
}
stage('backend tests') {
try {
sh "./gradlew test integrationTest -Pprod -PnodeInstall --no-daemon"
} catch(err) {
throw err
} finally {
junit '**/build/**/TEST-*.xml' } }
stage('frontend tests') {
try {
sh "./gradlew npm_run_test -Pprod -PnodeInstall --no-daemon"
} catch(err) {
throw err
} finally {
junit '**/build/test-results/TESTS-*.xml'
}
}
stage('packaging') {
sh "./gradlew bootJar -x test -Pprod -PnodeInstall --no-daemon"
archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true
}
stage ('Publish') {
nexusPublisher nexusInstanceId: 'stsnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: "${workspace}/build/libs/devopsdemo-${version}.jar"]], mavenCoordinate: [artifactId: 'devops-demo', groupId: 'com.simpletechnologysolutions', packaging: 'jar', version: "${version}" ]]]
}
stage('terraform init') {
dir('./terraform/prod'){
sh "echo 'Initializing Terraform'"
sh "terraform init -input=false"
}
}
stage('terraform plan'){
dir('./terraform/prod'){
sh "echo 'Planning Terraform Build'"
sh "terraform plan -var 'access_key=$ACCESS_KEY' -var 'secret_key=$SECRET_KEY'"
}
}
stage('terraform apply'){
steps {
script{
def apply = false
try {
input message: 'Can you please confirm the apply', ok: 'Ready to Apply the Config'
apply = true
} catch (err) {
apply = false
currentBuild.result = 'UNSTABLE'
}
if(apply){
dir('./terraform/prod'){
sh "echo 'Applying Terraform'"
sh 'terraform apply --auto-approve'
}
}
}
}
}
}