未验证 提交 642d52a4 编写于 作者: Z Zhuxiaoyang 提交者: GitHub

Merge pull request #406 from runzexia/jenkins-client-check

jenkins client NPE check
...@@ -32,6 +32,12 @@ import ( ...@@ -32,6 +32,12 @@ import (
func CreateProjectCredential(projectId, username string, credentialRequest *JenkinsCredential) (string, error) { func CreateProjectCredential(projectId, username string, credentialRequest *JenkinsCredential) (string, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.Id) err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.Id)
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
...@@ -139,6 +145,11 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk ...@@ -139,6 +145,11 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk
func UpdateProjectCredential(projectId, credentialId string, credentialRequest *JenkinsCredential) (string, error) { func UpdateProjectCredential(projectId, credentialId string, credentialRequest *JenkinsCredential) (string, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
jenkinsCredential, err := jenkinsClient.GetCredentialInFolder(credentialRequest.Domain, jenkinsCredential, err := jenkinsClient.GetCredentialInFolder(credentialRequest.Domain,
credentialId, credentialId,
projectId) projectId)
...@@ -228,6 +239,11 @@ func UpdateProjectCredential(projectId, credentialId string, credentialRequest * ...@@ -228,6 +239,11 @@ func UpdateProjectCredential(projectId, credentialId string, credentialRequest *
func DeleteProjectCredential(projectId, credentialId string, credentialRequest *JenkinsCredential) (string, error) { func DeleteProjectCredential(projectId, credentialId string, credentialRequest *JenkinsCredential) (string, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
dbClient := devops_mysql.OpenDatabase() dbClient := devops_mysql.OpenDatabase()
_, err := jenkinsClient.GetCredentialInFolder(credentialRequest.Domain, _, err := jenkinsClient.GetCredentialInFolder(credentialRequest.Domain,
credentialId, credentialId,
...@@ -262,6 +278,11 @@ func DeleteProjectCredential(projectId, credentialId string, credentialRequest * ...@@ -262,6 +278,11 @@ func DeleteProjectCredential(projectId, credentialId string, credentialRequest *
func GetProjectCredential(projectId, credentialId, domain, getContent string) (*JenkinsCredential, error) { func GetProjectCredential(projectId, credentialId, domain, getContent string) (*JenkinsCredential, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
dbClient := devops_mysql.OpenDatabase() dbClient := devops_mysql.OpenDatabase()
jenkinsResponse, err := jenkinsClient.GetCredentialInFolder(domain, jenkinsResponse, err := jenkinsClient.GetCredentialInFolder(domain,
credentialId, credentialId,
...@@ -318,7 +339,7 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (* ...@@ -318,7 +339,7 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
value, _ := selection.Attr("value") value, _ := selection.Attr("value")
content.Username = value content.Username = value
}) })
doc.Find("textarea[name*=privateKey]").Each(func(i int, selection *goquery.Selection) { doc.Find("textarea[name*=privateKey]").Each(func(i int, selection *goquery.Selection) {
value := selection.Text() value := selection.Text()
content.PrivateKey = value content.PrivateKey = value
...@@ -332,6 +353,11 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (* ...@@ -332,6 +353,11 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
func GetProjectCredentials(projectId, domain string) ([]*JenkinsCredential, error) { func GetProjectCredentials(projectId, domain string) ([]*JenkinsCredential, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
dbClient := devops_mysql.OpenDatabase() dbClient := devops_mysql.OpenDatabase()
jenkinsCredentialResponses, err := jenkinsClient.GetCredentialsInFolder(domain, projectId) jenkinsCredentialResponses, err := jenkinsClient.GetCredentialsInFolder(domain, projectId)
if err != nil { if err != nil {
...@@ -367,6 +393,11 @@ func insertCredentialToDb(projectId, credentialId, domain, username string) erro ...@@ -367,6 +393,11 @@ func insertCredentialToDb(projectId, credentialId, domain, username string) erro
func checkJenkinsCredentialExists(projectId, domain, credentialId string) error { func checkJenkinsCredentialExists(projectId, domain, credentialId string) error {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return restful.NewError(http.StatusServiceUnavailable, err.Error())
}
credential, err := jenkinsClient.GetCredentialInFolder(domain, credentialId, projectId) credential, err := jenkinsClient.GetCredentialInFolder(domain, credentialId, projectId)
if credential != nil { if credential != nil {
err := fmt.Errorf("credential id [%s] has been used", credential.Id) err := fmt.Errorf("credential id [%s] has been used", credential.Id)
......
...@@ -98,7 +98,12 @@ func GetProjectMember(projectId, username string) (*DevOpsProjectMembership, err ...@@ -98,7 +98,12 @@ func GetProjectMember(projectId, username string) (*DevOpsProjectMembership, err
func AddProjectMember(projectId, operator string, member *DevOpsProjectMembership) (*DevOpsProjectMembership, error) { func AddProjectMember(projectId, operator string, member *DevOpsProjectMembership) (*DevOpsProjectMembership, error) {
dbconn := devops_mysql.OpenDatabase() dbconn := devops_mysql.OpenDatabase()
jenkinsClinet := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
membership := &DevOpsProjectMembership{} membership := &DevOpsProjectMembership{}
err := dbconn.Select(DevOpsProjectMembershipColumns...). err := dbconn.Select(DevOpsProjectMembershipColumns...).
...@@ -118,13 +123,13 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi ...@@ -118,13 +123,13 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
return nil, restful.NewError(http.StatusInternalServerError, err.Error()) return nil, restful.NewError(http.StatusInternalServerError, err.Error())
} }
globalRole, err := jenkinsClinet.GetGlobalRole(JenkinsAllUserRoleName) globalRole, err := jenkinsClient.GetGlobalRole(JenkinsAllUserRoleName)
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
} }
if globalRole == nil { if globalRole == nil {
_, err := jenkinsClinet.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{ _, err := jenkinsClient.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{
GlobalRead: true, GlobalRead: true,
}, true) }, true)
if err != nil { if err != nil {
...@@ -137,7 +142,7 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi ...@@ -137,7 +142,7 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
} }
projectRole, err := jenkinsClinet.GetProjectRole(GetProjectRoleName(projectId, member.Role)) projectRole, err := jenkinsClient.GetProjectRole(GetProjectRoleName(projectId, member.Role))
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
...@@ -147,7 +152,7 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi ...@@ -147,7 +152,7 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
} }
pipelineRole, err := jenkinsClinet.GetProjectRole(GetPipelineRoleName(projectId, member.Role)) pipelineRole, err := jenkinsClient.GetProjectRole(GetPipelineRoleName(projectId, member.Role))
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
...@@ -181,7 +186,12 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi ...@@ -181,7 +186,12 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMembership) (*DevOpsProjectMembership, error) { func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMembership) (*DevOpsProjectMembership, error) {
dbconn := devops_mysql.OpenDatabase() dbconn := devops_mysql.OpenDatabase()
jenkinsClinet := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
oldMembership := &DevOpsProjectMembership{} oldMembership := &DevOpsProjectMembership{}
err := dbconn.Select(DevOpsProjectMembershipColumns...). err := dbconn.Select(DevOpsProjectMembershipColumns...).
From(DevOpsProjectMembershipTableName). From(DevOpsProjectMembershipTableName).
...@@ -194,7 +204,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember ...@@ -194,7 +204,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
return nil, restful.NewError(http.StatusBadRequest, err.Error()) return nil, restful.NewError(http.StatusBadRequest, err.Error())
} }
oldProjectRole, err := jenkinsClinet.GetProjectRole(GetProjectRoleName(projectId, oldMembership.Role)) oldProjectRole, err := jenkinsClient.GetProjectRole(GetProjectRoleName(projectId, oldMembership.Role))
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
...@@ -204,7 +214,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember ...@@ -204,7 +214,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
} }
oldPipelineRole, err := jenkinsClinet.GetProjectRole(GetPipelineRoleName(projectId, oldMembership.Role)) oldPipelineRole, err := jenkinsClient.GetProjectRole(GetPipelineRoleName(projectId, oldMembership.Role))
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
...@@ -215,7 +225,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember ...@@ -215,7 +225,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
} }
projectRole, err := jenkinsClinet.GetProjectRole(GetProjectRoleName(projectId, member.Role)) projectRole, err := jenkinsClient.GetProjectRole(GetProjectRoleName(projectId, member.Role))
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
...@@ -225,7 +235,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember ...@@ -225,7 +235,7 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
} }
pipelineRole, err := jenkinsClinet.GetProjectRole(GetPipelineRoleName(projectId, member.Role)) pipelineRole, err := jenkinsClient.GetProjectRole(GetPipelineRoleName(projectId, member.Role))
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error()) return nil, restful.NewError(utils.GetJenkinsStatusCode(err), err.Error())
...@@ -262,6 +272,11 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember ...@@ -262,6 +272,11 @@ func UpdateProjectMember(projectId, operator string, member *DevOpsProjectMember
func DeleteProjectMember(projectId, username string) (string, error) { func DeleteProjectMember(projectId, username string) (string, error) {
dbconn := devops_mysql.OpenDatabase() dbconn := devops_mysql.OpenDatabase()
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
oldMembership := &DevOpsProjectMembership{} oldMembership := &DevOpsProjectMembership{}
err := dbconn.Select(DevOpsProjectMembershipColumns...). err := dbconn.Select(DevOpsProjectMembershipColumns...).
From(DevOpsProjectMembershipTableName). From(DevOpsProjectMembershipTableName).
......
...@@ -24,6 +24,11 @@ import ( ...@@ -24,6 +24,11 @@ import (
func CreateProjectPipeline(projectId string, pipeline *ProjectPipeline) (string, error) { func CreateProjectPipeline(projectId string, pipeline *ProjectPipeline) (string, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
switch pipeline.Type { switch pipeline.Type {
case NoScmPipelineType: case NoScmPipelineType:
...@@ -89,6 +94,11 @@ func CreateProjectPipeline(projectId string, pipeline *ProjectPipeline) (string, ...@@ -89,6 +94,11 @@ func CreateProjectPipeline(projectId string, pipeline *ProjectPipeline) (string,
func DeleteProjectPipeline(projectId string, pipelineId string) (string, error) { func DeleteProjectPipeline(projectId string, pipelineId string) (string, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
_, err := jenkinsClient.DeleteJob(pipelineId, projectId) _, err := jenkinsClient.DeleteJob(pipelineId, projectId)
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
...@@ -99,6 +109,11 @@ func DeleteProjectPipeline(projectId string, pipelineId string) (string, error) ...@@ -99,6 +109,11 @@ func DeleteProjectPipeline(projectId string, pipelineId string) (string, error)
func UpdateProjectPipeline(projectId, pipelineId string, pipeline *ProjectPipeline) (string, error) { func UpdateProjectPipeline(projectId, pipelineId string, pipeline *ProjectPipeline) (string, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return "", restful.NewError(http.StatusServiceUnavailable, err.Error())
}
switch pipeline.Type { switch pipeline.Type {
case NoScmPipelineType: case NoScmPipelineType:
...@@ -155,7 +170,11 @@ func UpdateProjectPipeline(projectId, pipelineId string, pipeline *ProjectPipeli ...@@ -155,7 +170,11 @@ func UpdateProjectPipeline(projectId, pipelineId string, pipeline *ProjectPipeli
func GetProjectPipeline(projectId, pipelineId string) (*ProjectPipeline, error) { func GetProjectPipeline(projectId, pipelineId string) (*ProjectPipeline, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
job, err := jenkinsClient.GetJob(pipelineId, projectId) job, err := jenkinsClient.GetJob(pipelineId, projectId)
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
...@@ -205,6 +224,11 @@ func GetProjectPipeline(projectId, pipelineId string) (*ProjectPipeline, error) ...@@ -205,6 +224,11 @@ func GetProjectPipeline(projectId, pipelineId string) (*ProjectPipeline, error)
func GetPipelineSonar(projectId, pipelineId string) ([]*SonarStatus, error) { func GetPipelineSonar(projectId, pipelineId string) ([]*SonarStatus, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
job, err := jenkinsClient.GetJob(pipelineId, projectId) job, err := jenkinsClient.GetJob(pipelineId, projectId)
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
...@@ -238,6 +262,11 @@ func GetPipelineSonar(projectId, pipelineId string) ([]*SonarStatus, error) { ...@@ -238,6 +262,11 @@ func GetPipelineSonar(projectId, pipelineId string) ([]*SonarStatus, error) {
func GetMultiBranchPipelineSonar(projectId, pipelineId, branchId string) ([]*SonarStatus, error) { func GetMultiBranchPipelineSonar(projectId, pipelineId, branchId string) ([]*SonarStatus, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
job, err := jenkinsClient.GetJob(branchId, projectId, pipelineId) job, err := jenkinsClient.GetJob(branchId, projectId, pipelineId)
if err != nil { if err != nil {
glog.Errorf("%+v", err) glog.Errorf("%+v", err)
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/emicklei/go-restful"
"io/ioutil" "io/ioutil"
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/db" "kubesphere.io/kubesphere/pkg/db"
...@@ -35,6 +36,7 @@ import ( ...@@ -35,6 +36,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/redis" "kubesphere.io/kubesphere/pkg/simple/client/redis"
"kubesphere.io/kubesphere/pkg/utils/k8sutil" "kubesphere.io/kubesphere/pkg/utils/k8sutil"
"kubesphere.io/kubesphere/pkg/utils/sliceutil" "kubesphere.io/kubesphere/pkg/utils/sliceutil"
"net/http"
"regexp" "regexp"
"sort" "sort"
"strconv" "strconv"
...@@ -552,7 +554,11 @@ func DeleteUser(username string) error { ...@@ -552,7 +554,11 @@ func DeleteUser(username string) error {
devopsDb := devops_mysql.OpenDatabase() devopsDb := devops_mysql.OpenDatabase()
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return restful.NewError(http.StatusServiceUnavailable, err.Error())
}
_, err = devopsDb.DeleteFrom(devops.DevOpsProjectMembershipTableName). _, err = devopsDb.DeleteFrom(devops.DevOpsProjectMembershipTableName).
Where(db.And( Where(db.And(
db.Eq(devops.DevOpsProjectMembershipUsernameColumn, username), db.Eq(devops.DevOpsProjectMembershipUsernameColumn, username),
......
...@@ -112,6 +112,11 @@ func DeleteDevOpsProject(projectId, username string) error { ...@@ -112,6 +112,11 @@ func DeleteDevOpsProject(projectId, username string) error {
return restful.NewError(http.StatusForbidden, err.Error()) return restful.NewError(http.StatusForbidden, err.Error())
} }
gojenkins := admin_jenkins.Client() gojenkins := admin_jenkins.Client()
if gojenkins == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return restful.NewError(http.StatusServiceUnavailable, err.Error())
}
devopsdb := devops_mysql.OpenDatabase() devopsdb := devops_mysql.OpenDatabase()
_, err = gojenkins.DeleteJob(projectId) _, err = gojenkins.DeleteJob(projectId)
...@@ -158,6 +163,11 @@ func DeleteDevOpsProject(projectId, username string) error { ...@@ -158,6 +163,11 @@ func DeleteDevOpsProject(projectId, username string) error {
func CreateDevopsProject(username string, workspace string, req *devops.DevOpsProject) (*devops.DevOpsProject, error) { func CreateDevopsProject(username string, workspace string, req *devops.DevOpsProject) (*devops.DevOpsProject, error) {
jenkinsClient := admin_jenkins.Client() jenkinsClient := admin_jenkins.Client()
if jenkinsClient == nil {
err := fmt.Errorf("could not connect to jenkins")
glog.Error(err)
return nil, restful.NewError(http.StatusServiceUnavailable, err.Error())
}
devopsdb := devops_mysql.OpenDatabase() devopsdb := devops_mysql.OpenDatabase()
project := devops.NewDevOpsProject(req.Name, req.Description, username, req.Extra, workspace) project := devops.NewDevOpsProject(req.Name, req.Description, username, req.Extra, workspace)
_, err := jenkinsClient.CreateFolder(project.ProjectId, project.Description) _, err := jenkinsClient.CreateFolder(project.ProjectId, project.Description)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册