Change signature of CreateOrUpdateJob function
This commit is contained in:
parent
88d4f82e48
commit
d318bea4a1
|
|
@ -23,7 +23,7 @@ type Jenkins interface {
|
|||
CreateFolder(name string, parents ...string) (*gojenkins.Folder, error)
|
||||
CreateJobInFolder(config string, jobName string, parentIDs ...string) (*gojenkins.Job, error)
|
||||
CreateJob(config string, options ...interface{}) (*gojenkins.Job, error)
|
||||
CreateOrUpdateJob(config string, options ...interface{}) (*gojenkins.Job, error)
|
||||
CreateOrUpdateJob(config, jobName string) (*gojenkins.Job, bool, error)
|
||||
RenameJob(job string, name string) *gojenkins.Job
|
||||
CopyJob(copyFrom string, newName string) (*gojenkins.Job, error)
|
||||
DeleteJob(name string) (bool, error)
|
||||
|
|
@ -58,25 +58,19 @@ type jenkins struct {
|
|||
}
|
||||
|
||||
// CreateOrUpdateJob creates or updates a job from config
|
||||
func (jenkins *jenkins) CreateOrUpdateJob(config string, options ...interface{}) (*gojenkins.Job, error) {
|
||||
// taken from gojenkins.CreateJob
|
||||
qr := make(map[string]string)
|
||||
if len(options) > 0 {
|
||||
qr["name"] = options[0].(string)
|
||||
} else {
|
||||
return nil, errors.New("error creating job, job name is missing")
|
||||
}
|
||||
|
||||
func (jenkins *jenkins) CreateOrUpdateJob(config, jobName string) (job *gojenkins.Job, created bool, err error) {
|
||||
// create or update
|
||||
job, err := jenkins.GetJob(qr["name"])
|
||||
job, err = jenkins.GetJob(jobName)
|
||||
if isNotFoundError(err) {
|
||||
return jenkins.CreateJob(config, options...)
|
||||
job, err = jenkins.CreateJob(config, jobName)
|
||||
created = true
|
||||
return
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
err = job.UpdateConfig(config)
|
||||
return job, err
|
||||
return
|
||||
}
|
||||
|
||||
func isNotFoundError(err error) bool {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: /home/bartek/go/src/github.com/VirtusLab/jenkins-operator/pkg/controller/jenkins/client/jenkins.go
|
||||
// Source: pkg/controller/jenkins/client/jenkins.go
|
||||
|
||||
// Package mock_client is a generated GoMock package.
|
||||
package client
|
||||
|
|
@ -173,23 +173,19 @@ func (mr *MockJenkinsMockRecorder) CreateJob(config interface{}, options ...inte
|
|||
}
|
||||
|
||||
// CreateOrUpdateJob mocks base method
|
||||
func (m *MockJenkins) CreateOrUpdateJob(config string, options ...interface{}) (*gojenkins.Job, error) {
|
||||
func (m *MockJenkins) CreateOrUpdateJob(config, jobName string) (*gojenkins.Job, bool, error) {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []interface{}{config}
|
||||
for _, a := range options {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
ret := m.ctrl.Call(m, "CreateOrUpdateJob", varargs...)
|
||||
ret := m.ctrl.Call(m, "CreateOrUpdateJob", config, jobName)
|
||||
ret0, _ := ret[0].(*gojenkins.Job)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
ret1, _ := ret[1].(bool)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
}
|
||||
|
||||
// CreateOrUpdateJob indicates an expected call of CreateOrUpdateJob
|
||||
func (mr *MockJenkinsMockRecorder) CreateOrUpdateJob(config interface{}, options ...interface{}) *gomock.Call {
|
||||
func (mr *MockJenkinsMockRecorder) CreateOrUpdateJob(config, jobName interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
varargs := append([]interface{}{config}, options...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateJob", reflect.TypeOf((*MockJenkins)(nil).CreateOrUpdateJob), varargs...)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateJob", reflect.TypeOf((*MockJenkins)(nil).CreateOrUpdateJob), config, jobName)
|
||||
}
|
||||
|
||||
// RenameJob mocks base method
|
||||
|
|
|
|||
|
|
@ -63,10 +63,13 @@ func (s *SeedJobs) EnsureSeedJobs(jenkins *virtuslabv1alpha1.Jenkins) (done bool
|
|||
|
||||
// createJob is responsible for creating jenkins job which configures jenkins seed jobs and deploy keys
|
||||
func (s *SeedJobs) createJob() error {
|
||||
_, err := s.jenkinsClient.CreateOrUpdateJob(seedJobConfigXML, ConfigureSeedJobsName)
|
||||
_, created, err := s.jenkinsClient.CreateOrUpdateJob(seedJobConfigXML, ConfigureSeedJobsName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if created {
|
||||
s.logger.Info(fmt.Sprintf("'%s' job has been created", ConfigureSeedJobsName))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func TestEnsureSeedJobs(t *testing.T) {
|
|||
jenkinsClient.
|
||||
EXPECT().
|
||||
CreateOrUpdateJob(seedJobConfigXML, ConfigureSeedJobsName).
|
||||
Return(nil, nil)
|
||||
Return(nil, true, nil)
|
||||
|
||||
jenkinsClient.
|
||||
EXPECT().
|
||||
|
|
@ -69,7 +69,7 @@ func TestEnsureSeedJobs(t *testing.T) {
|
|||
jenkinsClient.
|
||||
EXPECT().
|
||||
CreateOrUpdateJob(seedJobConfigXML, ConfigureSeedJobsName).
|
||||
Return(nil, nil)
|
||||
Return(nil, false, nil)
|
||||
|
||||
jenkinsClient.
|
||||
EXPECT().
|
||||
|
|
|
|||
|
|
@ -40,10 +40,13 @@ func New(jenkinsClient jenkinsclient.Jenkins, k8sClient k8s.Client, logger logr.
|
|||
|
||||
// ConfigureGroovyJob configures jenkins job for executing groovy scripts
|
||||
func (g *Groovy) ConfigureGroovyJob() error {
|
||||
_, err := g.jenkinsClient.CreateOrUpdateJob(fmt.Sprintf(configurationJobXMLFmt, g.scriptsPath), g.jobName)
|
||||
_, created, err := g.jenkinsClient.CreateOrUpdateJob(fmt.Sprintf(configurationJobXMLFmt, g.scriptsPath), g.jobName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if created {
|
||||
g.logger.Info(fmt.Sprintf("'%s' job has been created", g.jobName))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue