-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
89 lines (86 loc) · 3.07 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
pipeline {
agent any
stages {
stage('\u27A1 Install ansible and dependanices') {
steps {
sh '''sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf install -y ansible wget unzip'''
}
}
stage('\u27A1 Install Packer') {
steps {
sh '''wget https://releases.hashicorp.com/packer/1.4.2/packer_1.4.2_linux_amd64.zip;
unzip packer_1.4.2_linux_amd64.zip;
$WORKSPACE/packer --version;
wget -O $WORKSPACE/packer-builder-vsphere-clone.linux https://github.com/jetbrains-infra/packer-builder-vsphere/releases/download/v2.3/packer-builder-vsphere-clone.linux;
chmod +x $WORKSPACE/packer-builder-vsphere-clone.linux;
'''
}
}
stage('\u27A1 Master-Inflate variables.json') {
when {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
steps {
sh 'cp /var/lib/jenkins/variables.json $WORKSPACE/debian10/variables.json'
}
}
stage('\u27A1 Inflate variables.json') {
when {
not {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
}
steps {
sh 'cp /var/lib/jenkins/notmaster-variables.json $WORKSPACE/debian10/notmaster-variables.json'
}
}
stage('\u27A1 Master-Build image with packer') {
when {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
steps {
sh '$WORKSPACE/packer build -var-file=$WORKSPACE/debian10/variables.json $WORKSPACE/debian10/debian.json'
}
}
stage('\u27A1 Build image with packer') {
when {
not {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
}
steps {
sh '$WORKSPACE/packer build -var-file=$WORKSPACE/debian10/notmaster-variables.json $WORKSPACE/debian10/debian.json'
}
}
stage('\u27A1 Master-Change VM to gold template and archive old template') {
when {
expression {
return env.GIT_BRANCH == "origin/master"
}
}
steps {
sh 'docker run --rm --entrypoint="/usr/bin/pwsh" -v $WORKSPACE/:/mnt vmware/powerclicore /mnt/.ciscripts/Convert-Machine-to-Gold-Template-and-archive.ps1'
}
}
stage('\u27A1 Gotta clean up after ourselves') {
steps {
sh '''sudo dnf -y remove ansible;
sudo dnf -y autoremove'''
}
}
}
post {
always {
sh 'rm -fr $WORKSPACE/*;'
}
}
}