Skip to content

Commit cf655d0

Browse files
author
Jason Schmidt
authored
chore: jenkins fixes and general cleanup of jenkinsfiles (#161)
* fix: typo in find command was causing pulumi stacks to not be deleted * fix: formatting and find syntax in jenkins (esc for Groovy) * fix: formatting and find syntax in jenkins (esc for Groovy) * chore: clean up the comments a bit
1 parent 0619d5d commit cf655d0

File tree

7 files changed

+115
-154
lines changed

7 files changed

+115
-154
lines changed

extras/jenkins/AWS/Jenkinsfile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pipeline {
7878
DEBIAN_FRONTEND=noninteractive apt -y upgrade
7979
# Make sure our deps are installed
8080
DEBIAN_FRONTEND=noninteractive apt -y install figlet openjdk-11-jdk make docker.io
81-
'''
81+
'''
8282
}
8383
}
8484

@@ -95,7 +95,7 @@ pipeline {
9595
sh '''
9696
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
9797
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkaws${BUILD_NUMBER} --force --yes \\;
98-
'''
98+
'''
9999
}
100100
}
101101

@@ -108,7 +108,7 @@ pipeline {
108108

109109
sh '''
110110
$WORKSPACE/bin/setup_venv.sh
111-
'''
111+
'''
112112

113113
}
114114
}
@@ -122,7 +122,7 @@ pipeline {
122122

123123
sh '''
124124
$WORKSPACE/bin/aws_write_creds.sh
125-
'''
125+
'''
126126

127127
}
128128
}
@@ -156,7 +156,7 @@ pipeline {
156156
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenkaws${BUILD_NUMBER}
157157
$WORKSPACE/pulumi/python/venv/bin/pulumi config set aws:profile "${AWS_PROFILE}" -C pulumi/python/config -s marajenkaws${BUILD_NUMBER}
158158
$WORKSPACE/pulumi/python/venv/bin/pulumi config set aws:region "${AWS_DEFAULT_REGION}" -C pulumi/python/config -s marajenkaws${BUILD_NUMBER}
159-
'''
159+
'''
160160
}
161161
}
162162

@@ -171,7 +171,7 @@ pipeline {
171171
sh '''
172172
echo "${NGINX_JWT}" > $WORKSPACE/extras/jwt.token
173173
$WORKSPACE/bin/start_aws.sh
174-
'''
174+
'''
175175
}
176176
}
177177

@@ -188,8 +188,8 @@ pipeline {
188188

189189
sh '''
190190
$WORKSPACE/bin/destroy.sh
191-
find . -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkaws${BUILD_NUMBER} --force --yes \;
192-
'''
191+
find . -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkaws${BUILD_NUMBER} --force --yes \\;
192+
'''
193193
}
194194
}
195195

@@ -204,10 +204,9 @@ pipeline {
204204
*/
205205

206206
sh '''
207-
# Destroy our partial build...
208-
$WORKSPACE/bin/destroy.sh || true
209-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
210-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkaws${BUILD_NUMBER} --force --yes \\;
207+
# Destroy our partial build...
208+
$WORKSPACE/bin/destroy.sh || true
209+
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkaws${BUILD_NUMBER} --force --yes \\;
211210
'''
212211
}
213212
}

extras/jenkins/DigitalOcean/Jenkinsfile

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pipeline {
7676
doctl auth init -t $DIGITALOCEAN_TOKEN
7777
# Fix perms for the snap....
7878
snap connect doctl:kube-config
79-
'''
79+
'''
8080
}
8181
}
8282

@@ -140,7 +140,7 @@ pipeline {
140140
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
141141
$WORKSPACE/pulumi/python/venv/bin/pulumi config set digitalocean:token "${DO_TOKEN}" --plaintext -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
142142
$WORKSPACE/pulumi/python/venv/bin/pulumi config set domk8s:k8s_version "latest" -C pulumi/python/config -s marajenkdo${BUILD_NUMBER}
143-
'''
143+
'''
144144

145145
}
146146
}
@@ -176,15 +176,9 @@ pipeline {
176176
find . -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir pulumi stack rm marajenkdo${BUILD_NUMBER} --force --yes \\;
177177
'''
178178
}
179-
/*
180-
* Clean up the environment; this includes running the destroy script to remove our pulumi resources and
181-
* destroy the deployed infrastructure in Digital Ocean.
182-
*
183-
* After that completes, we remove the pulumi stack from the project with the find command; this is because
184-
* we need to delete the stack in each project it's been instantiated in.
185-
*/}
186-
187179
}
180+
}
181+
188182
post {
189183
failure {
190184

@@ -194,11 +188,10 @@ pipeline {
194188
*/
195189

196190
sh '''
197-
# Destroy our partial build...
198-
$WORKSPACE/bin/destroy.sh || true
199-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
200-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \;
191+
# Destroy our partial build...
192+
$WORKSPACE/bin/destroy.sh || true
193+
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \\;
201194
'''
202195
}
203196
}
204-
}
197+
}

extras/jenkins/K3S/Jenkinsfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ pipeline {
227227
# Reset our K3S Environment
228228
/usr/local/bin/k3s-killall.sh || true
229229
/usr/local/bin/k3s-uninstall.sh || true
230-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
231-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \;
230+
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \\;
232231
'''
233232
}
234233
}

extras/jenkins/Linode/Jenkinsfile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ pipeline {
6969
# Create the directory for the kubeconfig
7070
mkdir -p $HOME/.kube || true
7171
chmod 777 $HOME/.kube || true
72-
'''
72+
'''
7373
}
7474
}
7575

7676
stage('Cleaning Up') {
7777
steps {
7878

7979
/*
80-
* Run a find and check for any stacks that currently exist with our generated stack name; this should not
81-
* happen in normal operation, but could potentially happen if things break so better safe than sorry.
80+
* This is currently empty since we are building a new executor for each run. However, maintaining
81+
* here for anyone who wants to add cleanup steps for their environment
8282
*
8383
* Other cleanup related functions can be placed here as well.
8484
*/
8585

8686
sh '''
87-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
88-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenklke${BUILD_NUMBER} --force --yes \\;
87+
# Just return...
88+
true
8989
'''
9090

9191
}
@@ -132,7 +132,7 @@ pipeline {
132132
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:adminpass "password" -C pulumi/python/config -s marajenklke${BUILD_NUMBER}
133133
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenklke${BUILD_NUMBER}
134134
$WORKSPACE/pulumi/python/venv/bin/pulumi config set linode:token "${LINODE_TOKEN}" --plaintext -C pulumi/python/config -s marajenklke${BUILD_NUMBER}
135-
'''
135+
'''
136136

137137
}
138138
}
@@ -165,7 +165,7 @@ pipeline {
165165

166166
sh '''
167167
PATH=$WORKSPACE/pulumi/python/venv/bin:$PATH $WORKSPACE/bin/destroy.sh
168-
find . -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir pulumi stack rm marajenklke${BUILD_NUMBER} --force --yes \\;
168+
find $WORKSPACE -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir pulumi stack rm marajenklke${BUILD_NUMBER} --force --yes \\;
169169
'''
170170
}
171171
}
@@ -180,11 +180,10 @@ pipeline {
180180
*/
181181

182182
sh '''
183-
# Destroy our partial build...
184-
$WORKSPACE/bin/destroy.sh || true
185-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
186-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \;
187-
'''
183+
# Destroy our partial build...
184+
$WORKSPACE/bin/destroy.sh || true
185+
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenklke${BUILD_NUMBER} --force --yes \\;
186+
'''
188187
}
189188
}
190189
}

extras/jenkins/MicroK8s/Jenkinsfile

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,25 @@ pipeline {
7171
DEBIAN_FRONTEND=noninteractive apt -y install figlet openjdk-11-jdk make docker.io
7272
# Make sure our kubeconfig dir exists…
7373
mkdir $HOME/.kube || true
74-
'''
74+
'''
7575
}
7676
}
7777

7878
stage('Cleaning Up') {
7979
steps {
8080

8181
/*
82-
* Run a find and check for any stacks that currently exist with our generated stack name; this should not
83-
* happen in normal operation, but could potentially happen if things break so better safe than sorry.
82+
* This is currently empty since we are building a new executor for each run. However, maintaining
83+
* here for anyone who wants to add cleanup steps for their environment
8484
*
85-
* This function also tries to remove both K3S and Microk8s if they are found on the host; this is because we
86-
* will be installing Microk8s and we want to both make sure we are removing any previous installations as well as
87-
* ensuring this Jenkins Agent does not already have a Microk8s installation on it.
85+
* Other cleanup related functions can be placed here as well.
8886
*/
8987

90-
sh '''
91-
# Reset our K3S Environment
92-
/usr/local/bin/k3s-killall.sh || true
93-
/usr/local/bin/k3s-uninstall.sh || true
94-
# Reset our Microk8s Environment; true if it’s not there
95-
microk8s reset --destroy-storage || true
96-
# True if it’s not there…
97-
snap remove microk8s || true
98-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
99-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \\;
100-
'''
101-
}
88+
sh '''
89+
# Just return...
90+
true
91+
'''
92+
}
10293
}
10394

10495
stage('Microk8s Setup') {
@@ -115,7 +106,7 @@ pipeline {
115106
snap install microk8s --classic --channel=1.23/stable
116107
microk8s.enable storage dns helm3
117108
microk8s.enable metallb 192.168.100.100/30
118-
'''
109+
'''
119110
}
120111
}
121112

@@ -129,7 +120,7 @@ pipeline {
129120

130121
sh '''
131122
microk8s.config > $HOME/.kube/config
132-
'''
123+
'''
133124
}
134125
}
135126

@@ -142,7 +133,7 @@ pipeline {
142133

143134
sh '''
144135
$WORKSPACE/bin/setup_venv.sh
145-
'''
136+
'''
146137
}
147138
}
148139

@@ -159,21 +150,21 @@ pipeline {
159150
*/
160151

161152
sh '''
162-
echo "PULUMI_STACK=marajenk${BUILD_NUMBER}" > $WORKSPACE/config/pulumi/environment
163-
$WORKSPACE/pulumi/python/venv/bin/pulumi stack select --create marajenk${BUILD_NUMBER} -C pulumi/python/config
164-
$WORKSPACE/pulumi/python/venv/bin/pulumi stack select --create marajenk${BUILD_NUMBER} -C pulumi/python/kubernetes/applications/sirius
165-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set certmgr:helm_timeout "600" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
166-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kic-helm:fqdn "marajenks${BUILD_NUMBER}.zathras.io" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
167-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kic-helm:helm_timeout "600" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
168-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kubernetes:cluster_name "microk8s-cluster" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
169-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kubernetes:infra_type "kubeconfig" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
170-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kubernetes:kubeconfig "$HOME/.kube/config" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
171-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set logagent:helm_timeout "600" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
172-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set logstore:helm_timeout "600" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
173-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:adminpass "password" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
174-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
175-
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenk${BUILD_NUMBER}
176-
'''
153+
echo "PULUMI_STACK=marajenkmk8s${BUILD_NUMBER}" > $WORKSPACE/config/pulumi/environment
154+
$WORKSPACE/pulumi/python/venv/bin/pulumi stack select --create marajenkmk8s${BUILD_NUMBER} -C pulumi/python/config
155+
$WORKSPACE/pulumi/python/venv/bin/pulumi stack select --create marajenkmk8s${BUILD_NUMBER} -C pulumi/python/kubernetes/applications/sirius
156+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set certmgr:helm_timeout "600" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
157+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kic-helm:fqdn "marajenkmk8ss${BUILD_NUMBER}.zathras.io" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
158+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kic-helm:helm_timeout "600" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
159+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kubernetes:cluster_name "microk8s-cluster" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
160+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kubernetes:infra_type "kubeconfig" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
161+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set kubernetes:kubeconfig "$HOME/.kube/config" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
162+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set logagent:helm_timeout "600" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
163+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set logstore:helm_timeout "600" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
164+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:adminpass "password" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
165+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
166+
$WORKSPACE/pulumi/python/venv/bin/pulumi config set prometheus:helm_timeout "600" -C pulumi/python/config -s marajenkmk8s${BUILD_NUMBER}
167+
'''
177168
}
178169
}
179170

@@ -188,7 +179,7 @@ pipeline {
188179
sh '''
189180
echo $NGINX_JWT > $WORKSPACE/extras/jwt.token
190181
$WORKSPACE/bin/start_kube.sh
191-
'''
182+
'''
192183
}
193184
}
194185

@@ -209,14 +200,8 @@ pipeline {
209200
microk8s reset --destroy-storage || true
210201
# True if it’s not there…
211202
sudo snap remove microk8s || true
212-
find . -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \\;
213-
# This is a hack to allow additional commands to be issued following cleanup. This is needed because the VMs
214-
# that currently run as agents for K3S and Microk8s deployments need to be rebooted following some number of
215-
# runs due to zombie processes and other issues. Long term we want to deploy these VM's via IaaC so the only
216-
# exist for the lifetime of the project. We do it this way in order to provide some flexibility for the
217-
# jenkins configuration.
218-
${POSTRUN_CMD- true}
219-
'''
203+
find . -mindepth 2 -maxdepth 6 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkmk8s${BUILD_NUMBER} --force --yes \\;
204+
'''
220205

221206
}
222207
}
@@ -233,14 +218,13 @@ pipeline {
233218
*/
234219

235220
sh '''
236-
# Destroy our partial build...
237-
$WORKSPACE/bin/destroy.sh || true
238-
# Reset our Microk8s Environment; true if it’s not there
239-
microk8s reset --destroy-storage || true
240-
# True if it’s not there…
241-
snap remove microk8s || true
242-
# Clean up the Pulumi stack if it exists for our run - which it shouldn\'t, but you never know.
243-
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenk${BUILD_NUMBER} --force --yes \;
221+
# Destroy our partial build...
222+
$WORKSPACE/bin/destroy.sh || true
223+
# Reset our Microk8s Environment; true if it’s not there
224+
microk8s reset --destroy-storage || true
225+
# True if it’s not there…
226+
snap remove microk8s || true
227+
find $WORKSPACE -mindepth 2 -maxdepth 7 -type f -name Pulumi.yaml -execdir $WORKSPACE/pulumi/python/venv/bin/pulumi stack rm marajenkmk8s${BUILD_NUMBER} --force --yes \\;
244228
'''
245229
}
246230
}

0 commit comments

Comments
 (0)