未验证 提交 8ba8078a 编写于 作者: R runzexia 提交者: GitHub

Merge pull request #391 from runzexia/reinit-jenkins-

retry init if jenkinsClient == nil
......@@ -695,7 +695,7 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("limit", "limit count").
Required(false).
DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK,[]devops.NodeSteps{}).
Returns(http.StatusOK, RespOK, []devops.NodeSteps{}).
Writes([]devops.NodeSteps{}))
// match /blue/rest/organizations/jenkins/pipelines/%s/%s/runs/%s/nodes/%s/steps/?limit=
......@@ -721,7 +721,7 @@ func addWebService(c *restful.Container) error {
Produces("application/json", "charset=utf-8").
Doc("Json to Jenkinsfile.").
Reads(devops.ReqJson{}).
Returns(http.StatusOK, RespOK,devops.NodeSteps{}).
Returns(http.StatusOK, RespOK, devops.NodeSteps{}).
Writes(devops.ResJenkinsfile{}))
// match /pipeline-model-converter/toJson
......@@ -732,7 +732,7 @@ func addWebService(c *restful.Container) error {
Produces("application/json", "charset=utf-8").
Doc("Jenkinsfile to Json.").
Reads(devops.ReqJenkinsfile{}).
Returns(http.StatusOK, RespOK,devops.ResJson{}).
Returns(http.StatusOK, RespOK, devops.ResJson{}).
Writes(devops.ResJson{}))
// match /git/notifyCommit/?url=
......
......@@ -21,7 +21,7 @@ import (
)
var (
jenkinsClientOnce sync.Once
jenkinsInitMutex sync.Mutex
jenkinsClient *gojenkins.Jenkins
jenkinsAdminAddress string
jenkinsAdminUsername string
......@@ -41,35 +41,36 @@ func init() {
}
func Client() *gojenkins.Jenkins {
jenkinsClientOnce.Do(func() {
jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword)
jenkins, err := jenkins.Init()
if err != nil {
glog.Error("failed to connect jenkins")
return
}
jenkinsClient = jenkins
globalRole, err := jenkins.GetGlobalRole(JenkinsAllUserRoleName)
if err != nil {
glog.Error("failed to get jenkins role")
}
if globalRole == nil {
_, err := jenkins.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{
GlobalRead: true,
if jenkinsClient == nil {
jenkinsInitMutex.Lock()
defer jenkinsInitMutex.Unlock()
if jenkinsClient == nil {
jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword)
jenkins, err := jenkins.Init()
if err != nil {
glog.Errorf("failed to connect jenkins, %+v", err)
}
globalRole, err := jenkins.GetGlobalRole(JenkinsAllUserRoleName)
if err != nil {
glog.Errorf("failed to get jenkins role, %+v", err)
}
if globalRole == nil {
_, err := jenkins.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{
GlobalRead: true,
}, true)
if err != nil {
glog.Errorf("failed to create jenkins global role, %+v", err)
}
}
_, err = jenkins.AddProjectRole(JenkinsAllUserRoleName, "\\n\\s*\\r", gojenkins.ProjectPermissionIds{
SCMTag: true,
}, true)
if err != nil {
glog.Error("failed to create jenkins global role")
return
glog.Errorf("failed to create jenkins project role, %+v", err)
}
jenkinsClient = jenkins
}
_, err = jenkins.AddProjectRole(JenkinsAllUserRoleName, "\\n\\s*\\r", gojenkins.ProjectPermissionIds{
SCMTag: true,
}, true)
if err != nil {
glog.Error("failed to create jenkins project role")
return
}
})
}
return jenkinsClient
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册