-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuildCustomAMI-Jenkinsfile
70 lines (63 loc) · 2.45 KB
/
BuildCustomAMI-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
properties([
parameters([
choice(choices: ['dev', 'preprod', 'prod'],description: '', name: 'ENV'),
choice(choices: ['website', 'utils', 'fail2ban', 'nginx', 'mongodb', 'certbot'],description: '', name: 'ROLE'),
string(defaultValue: 'WebApache', description: '', name: 'APP_NAME', trim: false),
string(defaultValue: '443', description: '', name: 'APP_PORT', trim: false),
string(defaultValue: 'us-east-1', description: '', name: 'APP_REGION', trim: false),
string(defaultValue: 'https://github.com/cloudacademy/static-website-example', description: '', name: 'APP_REPO', trim: false)
]),
disableConcurrentBuilds(),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '1', numToKeepStr: '3'))
])
pipeline {
agent any
environment {
GitBranch = "master"
def ec2_ip = sh(script: 'curl http://169.254.169.254/latest/meta-data/public-ipv4', returnStdout: true)
}
stages {
stage('Check Vars') {
steps {
sh "echo check first if vars are compliant"
sh "echo ENV: $ENV"
sh "echo ENV: $ROLE"
sh "echo APP_NAME: $APP_NAME"
sh "echo APP_REGION: $APP_REGION"
sh "echo APP_PORT: $APP_PORT"
sh "echo APP_REPO: $APP_REPO"
}
}
stage('Clean Jenkins Workspace') {
steps {
cleanWs()
}
}
stage('Get git repository') {
steps {
git(
url: 'https://github.com/zfiel/Build_Custom_AMI.git',
credentialsId: 'e7aa4132-ba7d-44ff-aaef-366463f7dcc2',
branch: "${GitBranch}"
)
}
}
stage('Build AMI') {
steps {
dir ("packer"){
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
sh "packer build \
-var ec2_ip=$ec2_ip \
-var env=$ENV \
-var app_repo=$APP_REPO \
-var app_name=$APP_NAME \
-var app_port=$APP_PORT \
-var app_region=$APP_REGION \
-var role=$ROLE \
buildAMI.json"
}
}
}
}
}
}