blob: c49c2483a535d989a680a6a8e51c10b538d6eb21 [file] [log] [blame]
Giorgi Lekveishvili35982662024-04-05 13:05:40 +04001{{- $jenkinsHome := .Values.controller.jenkinsHome -}}
2
3apiVersion: v1
4kind: ConfigMap
5metadata:
6 name: {{ template "jenkins.fullname" . }}
7 namespace: {{ template "jenkins.namespace" . }}
8 labels:
gio20157e82026-07-22 13:10:48 +04009 {{ include "jenkins.labels" . | nindent 4 }}
Giorgi Lekveishvili35982662024-04-05 13:05:40 +040010data:
11 apply_config.sh: |-
12 set -e
13{{- if .Values.controller.initializeOnce }}
14 if [ -f {{ .Values.controller.jenkinsHome }}/initialization-completed ]; then
15 echo "controller was previously initialized, refusing to re-initialize"
16 exit 0
17 fi
18{{- end }}
19 echo "disable Setup Wizard"
20 # Prevent Setup Wizard when JCasC is enabled
21 echo $JENKINS_VERSION > {{ .Values.controller.jenkinsHome }}/jenkins.install.UpgradeWizard.state
22 echo $JENKINS_VERSION > {{ .Values.controller.jenkinsHome }}/jenkins.install.InstallUtil.lastExecVersion
23{{- if .Values.controller.overwritePlugins }}
24 echo "remove all plugins from shared volume"
25 # remove all plugins from shared volume
26 rm -rf {{ .Values.controller.jenkinsHome }}/plugins/*
27{{- end }}
28{{- if .Values.controller.JCasC.overwriteConfiguration }}
29 echo "deleting all XML config files"
30 rm -f {{ .Values.controller.jenkinsHome }}/config.xml
31 rm -f {{ .Values.controller.jenkinsHome }}/*plugins*.xml
32 find {{ .Values.controller.jenkinsHome }} -maxdepth 1 -type f -iname '*configuration*.xml' -exec rm -f {} \;
33{{- end }}
34{{- if .Values.controller.installPlugins }}
35 echo "download plugins"
36 # Install missing plugins
37 cp /var/jenkins_config/plugins.txt {{ .Values.controller.jenkinsHome }};
38 rm -rf {{ .Values.controller.jenkinsRef }}/plugins/*.lock
39 version () { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
40 if [ -f "{{ .Values.controller.jenkinsWar }}" ] && [ -n "$(command -v jenkins-plugin-cli)" 2>/dev/null ] && [ $(version $(jenkins-plugin-cli --version)) -ge $(version "2.1.1") ]; then
41 jenkins-plugin-cli --verbose --war "{{ .Values.controller.jenkinsWar }}" --plugin-file "{{ .Values.controller.jenkinsHome }}/plugins.txt" --latest {{ .Values.controller.installLatestPlugins }}{{- if .Values.controller.installLatestSpecifiedPlugins }} --latest-specified{{- end }};
42 else
43 /usr/local/bin/install-plugins.sh `echo $(cat {{ .Values.controller.jenkinsHome }}/plugins.txt)`;
44 fi
45 echo "copy plugins to shared volume"
46 # Copy plugins to shared volume
47 yes n | cp -i {{ .Values.controller.jenkinsRef }}/plugins/* /var/jenkins_plugins/;
48{{- end }}
49 {{- if not .Values.controller.sidecars.configAutoReload.enabled }}
50 echo "copy configuration as code files"
51 mkdir -p {{ .Values.controller.jenkinsHome }}/casc_configs;
52 rm -rf {{ .Values.controller.jenkinsHome }}/casc_configs/*
53 {{- if or .Values.controller.JCasC.defaultConfig .Values.controller.JCasC.configScripts }}
54 cp -v /var/jenkins_config/*.yaml {{ .Values.controller.jenkinsHome }}/casc_configs
55 {{- end }}
56 {{- end }}
57 echo "finished initialization"
58{{- if .Values.controller.initializeOnce }}
59 touch {{ .Values.controller.jenkinsHome }}/initialization-completed
60{{- end }}
61 {{- if not .Values.controller.sidecars.configAutoReload.enabled }}
62# Only add config to this script if we aren't auto-reloading otherwise the pod will restart upon each config change:
63{{- if .Values.controller.JCasC.defaultConfig }}
64 jcasc-default-config.yaml: |-
65 {{- include "jenkins.casc.defaults" . |nindent 4}}
66{{- end }}
67{{- range $key, $val := .Values.controller.JCasC.configScripts }}
68 {{ $key }}.yaml: |-
69{{ tpl $val $| indent 4 }}
70{{- end }}
71{{- end }}
72 plugins.txt: |-
73{{- if .Values.controller.installPlugins }}
74 {{- range $installPlugin := .Values.controller.installPlugins }}
75 {{- $installPlugin | nindent 4 }}
76 {{- end }}
77 {{- range $addlPlugin := .Values.controller.additionalPlugins }}
78 {{- /* duplicate plugin check */}}
79 {{- range $installPlugin := $.Values.controller.installPlugins }}
80 {{- if eq (splitList ":" $addlPlugin | first) (splitList ":" $installPlugin | first) }}
81 {{- $message := print "[PLUGIN CONFLICT] controller.additionalPlugins contains '" $addlPlugin "'" }}
82 {{- $message := print $message " but controller.installPlugins already contains '" $installPlugin "'." }}
83 {{- $message := print $message " Override controller.installPlugins to use '" $addlPlugin "' plugin." }}
84 {{- fail $message }}
85 {{- end }}
86 {{- end }}
87 {{- $addlPlugin | nindent 4 }}
88 {{- end }}
89{{- end }}