Fix trigger jenkins-operator-user-configuration-casc job when secret has changed
This commit is contained in:
		
							parent
							
								
									7eb03a6de5
								
							
						
					
					
						commit
						ccc0307bc1
					
				|  | @ -45,9 +45,7 @@ func New(jenkinsClient jenkinsclient.Jenkins, k8sClient k8s.Client, logger logr. | ||||||
| 
 | 
 | ||||||
| // ConfigureJob configures jenkins job which configures Jenkins with help Configuration as a code plugin
 | // ConfigureJob configures jenkins job which configures Jenkins with help Configuration as a code plugin
 | ||||||
| func (g *ConfigurationAsCode) ConfigureJob() error { | func (g *ConfigurationAsCode) ConfigureJob() error { | ||||||
| 	_, created, err := g.jenkinsClient.CreateOrUpdateJob( | 	_, created, err := g.jenkinsClient.CreateOrUpdateJob(configurationJobXMLFmt, g.jobName) | ||||||
| 		fmt.Sprintf(configurationJobXMLFmt, resources.UserConfigurationSecretVolumePath, resources.JenkinsUserConfigurationVolumePath), |  | ||||||
| 		g.jobName) |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | @ -62,15 +60,15 @@ func (g *ConfigurationAsCode) Ensure(jenkins *v1alpha1.Jenkins) (bool, error) { | ||||||
| 	jobsClient := jobs.New(g.jenkinsClient, g.k8sClient, g.logger) | 	jobsClient := jobs.New(g.jenkinsClient, g.k8sClient, g.logger) | ||||||
| 
 | 
 | ||||||
| 	configuration := &corev1.ConfigMap{} | 	configuration := &corev1.ConfigMap{} | ||||||
| 	namespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetUserConfigurationConfigMapNameFromJenkins(jenkins)} | 	ConfigMapNamespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetUserConfigurationConfigMapNameFromJenkins(jenkins)} | ||||||
| 	err := g.k8sClient.Get(context.TODO(), namespaceName, configuration) | 	err := g.k8sClient.Get(context.TODO(), ConfigMapNamespaceName, configuration) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return false, errors.WithStack(err) | 		return false, errors.WithStack(err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	secret := &corev1.Secret{} | 	secret := &corev1.Secret{} | ||||||
| 	namespaceName = types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetUserConfigurationSecretNameFromJenkins(jenkins)} | 	secretNamespaceName := types.NamespacedName{Namespace: jenkins.Namespace, Name: resources.GetUserConfigurationSecretNameFromJenkins(jenkins)} | ||||||
| 	err = g.k8sClient.Get(context.TODO(), namespaceName, configuration) | 	err = g.k8sClient.Get(context.TODO(), secretNamespaceName, secret) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return false, errors.WithStack(err) | 		return false, errors.WithStack(err) | ||||||
| 	} | 	} | ||||||
|  | @ -151,13 +149,13 @@ const configurationJobXMLFmt = `<?xml version='1.1' encoding='UTF-8'?> | ||||||
|   <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.61.1"> |   <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.61.1"> | ||||||
|     <script>import io.jenkins.plugins.casc.yaml.YamlSource; |     <script>import io.jenkins.plugins.casc.yaml.YamlSource; | ||||||
| 
 | 
 | ||||||
| def secretsPath = '%s' | def secretsPath = '` + resources.UserConfigurationSecretVolumePath + `' | ||||||
| def configsPath = '%s' | def configsPath = '` + resources.JenkinsUserConfigurationVolumePath + `' | ||||||
| def userConfigurationSecretExpectedHash = params.` + userConfigurationSecretHashParameterName + ` | def userConfigurationSecretExpectedHash = params.` + userConfigurationSecretHashParameterName + ` | ||||||
| def userConfigurationExpectedHash = params.` + userConfigurationHashParameterName + ` | def userConfigurationExpectedHash = params.` + userConfigurationHashParameterName + ` | ||||||
| 
 | 
 | ||||||
| node('master') { | node('master') { | ||||||
|     def secretsText = sh(script: "ls ${secretsPath} | grep .yaml | sort", returnStdout: true).trim() |     def secretsText = sh(script: "ls ${secretsPath} | sort", returnStdout: true).trim() | ||||||
|     def secrets = [] |     def secrets = [] | ||||||
|     secrets.addAll(secretsText.tokenize('\n')) |     secrets.addAll(secretsText.tokenize('\n')) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue