feat(skipPlugins): check whether base plugins are installed
This commit is contained in:
		
							parent
							
								
									9f8a5376f9
								
							
						
					
					
						commit
						472902f1db
					
				|  | @ -361,6 +361,11 @@ func (in *JenkinsMaster) DeepCopyInto(out *JenkinsMaster) { | ||||||
| 		*out = new(bool) | 		*out = new(bool) | ||||||
| 		**out = **in | 		**out = **in | ||||||
| 	} | 	} | ||||||
|  | 	if in.SkipPlugins != nil { | ||||||
|  | 		in, out := &in.SkipPlugins, &out.SkipPlugins | ||||||
|  | 		*out = new(bool) | ||||||
|  | 		**out = **in | ||||||
|  | 	} | ||||||
| 	if in.HostAliases != nil { | 	if in.HostAliases != nil { | ||||||
| 		in, out := &in.HostAliases, &out.HostAliases | 		in, out := &in.HostAliases, &out.HostAliases | ||||||
| 		*out = make([]corev1.HostAlias, len(*in)) | 		*out = make([]corev1.HostAlias, len(*in)) | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ package resources | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"strings" | ||||||
| 	"text/template" | 	"text/template" | ||||||
| 
 | 
 | ||||||
| 	"github.com/jenkinsci/kubernetes-operator/api/v1alpha2" | 	"github.com/jenkinsci/kubernetes-operator/api/v1alpha2" | ||||||
|  | @ -14,6 +15,8 @@ import ( | ||||||
| 
 | 
 | ||||||
| const installPluginsCommand = "jenkins-plugin-cli" | const installPluginsCommand = "jenkins-plugin-cli" | ||||||
| 
 | 
 | ||||||
|  | var requiredBasePlugins = []string{"configuration-as-code", "git", "job-dsl", "kubernetes", "kubernetes-credentials-provider", "workflow-aggregator"} | ||||||
|  | 
 | ||||||
| var initBashTemplate = template.Must(template.New(InitScriptName).Parse(`#!/usr/bin/env bash | var initBashTemplate = template.Must(template.New(InitScriptName).Parse(`#!/usr/bin/env bash | ||||||
| set -e | set -e | ||||||
| set -x | set -x | ||||||
|  | @ -59,6 +62,18 @@ EOF | ||||||
| 
 | 
 | ||||||
| {{ $installPluginsCommand }} --verbose --latest {{ .LatestPlugins }} -f {{ .JenkinsHomePath }}/user-plugins.txt | {{ $installPluginsCommand }} --verbose --latest {{ .LatestPlugins }} -f {{ .JenkinsHomePath }}/user-plugins.txt | ||||||
| echo "Installing plugins required by user - end" | echo "Installing plugins required by user - end" | ||||||
|  | {{else}} | ||||||
|  | echo "Skipping installation if plugins" | ||||||
|  | echo "Checking if required base plugins are installed" | ||||||
|  | installedPlugins=$(jenkins-plugin-cli --list 2> /dev/null) | ||||||
|  | for plugin in {{ .RequiredBasePlugins }}; do | ||||||
|  | 	if ! echo "$installedPlugins" | grep -q "^$plugin "; then | ||||||
|  | 		echo "Required base plugin $plugin not installed, exiting" | ||||||
|  | 		exit 1 | ||||||
|  | 	else | ||||||
|  | 		echo "Found $plugin" | ||||||
|  | 	fi | ||||||
|  | done | ||||||
| {{end}} | {{end}} | ||||||
| `)) | `)) | ||||||
| 
 | 
 | ||||||
|  | @ -84,6 +99,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) { | ||||||
| 		JenkinsHomePath          string | 		JenkinsHomePath          string | ||||||
| 		InitConfigurationPath    string | 		InitConfigurationPath    string | ||||||
| 		InstallPluginsCommand    string | 		InstallPluginsCommand    string | ||||||
|  | 		RequiredBasePlugins      string | ||||||
| 		JenkinsScriptsVolumePath string | 		JenkinsScriptsVolumePath string | ||||||
| 		BasePlugins              []v1alpha2.Plugin | 		BasePlugins              []v1alpha2.Plugin | ||||||
| 		UserPlugins              []v1alpha2.Plugin | 		UserPlugins              []v1alpha2.Plugin | ||||||
|  | @ -95,6 +111,7 @@ func buildInitBashScript(jenkins *v1alpha2.Jenkins) (*string, error) { | ||||||
| 		BasePlugins:              jenkins.Spec.Master.BasePlugins, | 		BasePlugins:              jenkins.Spec.Master.BasePlugins, | ||||||
| 		UserPlugins:              jenkins.Spec.Master.Plugins, | 		UserPlugins:              jenkins.Spec.Master.Plugins, | ||||||
| 		InstallPluginsCommand:    installPluginsCommand, | 		InstallPluginsCommand:    installPluginsCommand, | ||||||
|  | 		RequiredBasePlugins:      strings.Join(requiredBasePlugins, " "), | ||||||
| 		JenkinsScriptsVolumePath: JenkinsScriptsVolumePath, | 		JenkinsScriptsVolumePath: JenkinsScriptsVolumePath, | ||||||
| 		LatestPlugins:            *latestP, | 		LatestPlugins:            *latestP, | ||||||
| 		SkipPlugins:              *skipPlugins, | 		SkipPlugins:              *skipPlugins, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue