-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
67 lines (66 loc) · 1.95 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
pipeline {
agent any
tools {
maven 'apache-maven-3.5.2'
}
environment {
TERRAFORM_HOME = tool name: 'terraform', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
PATH = "$TERRAFORM_HOME:$PATH"
AWS_ACCESS_KEY_ID = credentials('aws-access-key-id')
AWS_SECRET_ACCESS_KEY = credentials('aws-secret-access-key')
REGISTRY_AUTH = credentials("dockerhub-credentials")
IMAGE_NAME = "${REGISTRY_AUTH_USR}/webapp"
TAGGED_IMAGE_NAME = "${IMAGE_NAME}:${env.BUILD_ID}"
}
stages {
stage('Build') {
steps {
echo 'Building...'
sh "mvn clean install"
}
}
stage('Package') {
steps {
echo 'Packaging...'
sh "docker build -t ${TAGGED_IMAGE_NAME} ."
}
}
stage('Publish') {
steps {
echo 'Publishing...'
sh '''
docker login -u=${REGISTRY_AUTH_USR} -p=${REGISTRY_AUTH_PSW}
docker tag ${TAGGED_IMAGE_NAME} ${IMAGE_NAME}:latest
docker push ${TAGGED_IMAGE_NAME}
docker push ${IMAGE_NAME}:latest
'''
}
}
stage('Deploy Plan') {
steps {
dir("deployment") {
echo 'Deploying....'
sh "terraform init"
sh "terraform get -update=true"
sh "terraform plan -input=false -out=tfplan -var \"docker_image=${TAGGED_IMAGE_NAME}\" -var \"aws_access_key=${AWS_ACCESS_KEY_ID}\" -var \"aws_secret_key=${AWS_SECRET_ACCESS_KEY}\""
}
}
}
stage('Deploy Apply') {
steps {
dir("deployment") {
echo 'Deploying....'
sh "terraform apply -input=false tfplan "
}
}
}
stage('Test') {
steps {
dir("deployment") {
echo 'Testing...'
sh "terraform show"
}
}
}
}
}