config.yaml 4.2 KB

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