-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
51 lines (50 loc) · 1.36 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
pipeline {
agent any
parameters {
string(
name: 'AWS_REGION',
defaultValue: 'eu-west-2',
description: 'Where do you wish to build an image?'
)
}
environment {
AWS_ACCESS_KEY_ID = credentials('JenkinsPacker_Public')
AWS_SECRET_ACCESS_KEY = credentials('JenkinsPacker_Private')
AWS_REGION = "${env.AWS_REGION}"
PACKER_AMI = sh(script: "aws ec2 describe-images --owner self --query 'Images[*].{ID:ImageId}' | grep -o '\".*\"' | sed 's/\"//g' | cut -d\":\" -f2")
}
stages {
stage('Checkout SCM') {
steps {
checkout scm
slackSend "Completed the packer build in ${params.AWS_REGION}, New AMI ${env.PACKER_AMI}"
}
}
stage('Validate') {
steps {
dir('packer-images/') {
sh "packer validate ${params.AWS_REGION}-ubuntu1604.json"
slackSend "Your ${params.AWS_REGION} packer image validated!"
}
}
}
stage('Build') {
steps {
dir('packer-images/') {
slackSend "Starting packer build in ${params.AWS_REGION}"
sh "packer build -debug ${params.AWS_REGION}-ubuntu1604.json"
}
}
}
stage('Cleanup') {
steps {
cleanWs()
}
}
stage('Slack Notify') {
steps {
slackSend "Completed the packer build in ${params.AWS_REGION}, New AMI ${env.PACKER_AMI}"
}
}
}
}