Skip to content

Commit

Permalink
feat(skipPlugins): add option to skip install of plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
LEDfan committed Sep 27, 2024
1 parent 7cdffbe commit fbaffc4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha2/jenkins_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ type JenkinsMaster struct {
// +optional
LatestPlugins *bool `json:"latestPlugins,omitempty"`

// Allow to skip installation of both BasePlugins and Plugins.
// Requires using a custom image which includes the BasePlugins.
// Defaults to false.
// +optional
SkipPlugins *bool `json:"skipPlugins,omitempty"`

// DisableCSRFProtection allows you to toggle CSRF Protection on Jenkins
DisableCSRFProtection bool `json:"disableCSRFProtection"`

Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/jenkins.io_jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ spec:
description: Master represents Jenkins master pod properties and Jenkins
plugins. Every single change here requires a pod restart.
properties:
skipPlugins:
description: Allow to skip installation of both BasePlugins and Plugins. Requires using a custom image which includes the BasePlugins. Defaults to false.
type: boolean
annotations:
additionalProperties:
type: string
Expand Down
3 changes: 3 additions & 0 deletions pkg/configuration/base/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
)

func (r *JenkinsBaseConfigurationReconciler) verifyPlugins(jenkinsClient jenkinsclient.Jenkins) (bool, error) {
if r.Configuration.Jenkins.Spec.Master.SkipPlugins != nil && *r.Configuration.Jenkins.Spec.Master.SkipPlugins {
return true, nil
}
allPluginsInJenkins, err := jenkinsClient.GetPlugins(fetchAllPlugins)
if err != nil {
return false, stackerr.WithStack(err)
Expand Down
9 changes: 9 additions & 0 deletions pkg/configuration/base/resources/scripts_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mkdir -p {{ .JenkinsHomePath }}/scripts
cp {{ .JenkinsScriptsVolumePath }}/*.sh {{ .JenkinsHomePath }}/scripts
chmod +x {{ .JenkinsHomePath }}/scripts/*.sh
{{if not .SkipPlugins }}
{{- $jenkinsHomePath := .JenkinsHomePath }}
{{- $installPluginsCommand := .InstallPluginsCommand }}
Expand All @@ -58,6 +59,7 @@ EOF
{{ $installPluginsCommand }} --verbose --latest {{ .LatestPlugins }} -f {{ .JenkinsHomePath }}/user-plugins.txt
echo "Installing plugins required by user - end"
{{end}}
`))

func buildConfigMapTypeMeta() metav1.TypeMeta {
Expand All @@ -73,6 +75,11 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
latestP = new(bool)
*latestP = true
}
skipPlugins := jenkins.Spec.Master.SkipPlugins
if skipPlugins == nil {
skipPlugins = new(bool)
*skipPlugins = false
}
data := struct {
JenkinsHomePath string
InitConfigurationPath string
Expand All @@ -81,6 +88,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
BasePlugins []v1alpha2.Plugin
UserPlugins []v1alpha2.Plugin
LatestPlugins bool
SkipPlugins bool
}{
JenkinsHomePath: getJenkinsHomePath(jenkins),
InitConfigurationPath: jenkinsInitConfigurationVolumePath,
Expand All @@ -89,6 +97,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) {
InstallPluginsCommand: installPluginsCommand,
JenkinsScriptsVolumePath: JenkinsScriptsVolumePath,
LatestPlugins: *latestP,
SkipPlugins: *skipPlugins,
}

output, err := render.Render(initBashTemplate, data)
Expand Down

0 comments on commit fbaffc4

Please sign in to comment.