未验证 提交 b7889e41 编写于 作者: R runzexia

jenkins init

Signed-off-by: Nrunzexia <runzexia@yunify.com>
上级 ac961011
...@@ -590,7 +590,7 @@ func addWebService(c *restful.Container) error { ...@@ -590,7 +590,7 @@ func addWebService(c *restful.Container) error {
Param(webservice.QueryParameter("limit", "limit count"). Param(webservice.QueryParameter("limit", "limit count").
Required(false). Required(false).
DataFormat("limit=%d")). DataFormat("limit=%d")).
Returns(http.StatusOK, RespOK,[]devops.NodeSteps{}). Returns(http.StatusOK, RespOK, []devops.NodeSteps{}).
Writes([]devops.NodeSteps{})) Writes([]devops.NodeSteps{}))
// match /pipeline-model-converter/toJenkinsfile // match /pipeline-model-converter/toJenkinsfile
...@@ -601,7 +601,7 @@ func addWebService(c *restful.Container) error { ...@@ -601,7 +601,7 @@ func addWebService(c *restful.Container) error {
Produces("application/json", "charset=utf-8"). Produces("application/json", "charset=utf-8").
Doc("Json to Jenkinsfile."). Doc("Json to Jenkinsfile.").
Reads(devops.ReqJson{}). Reads(devops.ReqJson{}).
Returns(http.StatusOK, RespOK,devops.NodeSteps{}). Returns(http.StatusOK, RespOK, devops.NodeSteps{}).
Writes(devops.ResJenkinsfile{})) Writes(devops.ResJenkinsfile{}))
// match /pipeline-model-converter/toJson // match /pipeline-model-converter/toJson
...@@ -612,7 +612,7 @@ func addWebService(c *restful.Container) error { ...@@ -612,7 +612,7 @@ func addWebService(c *restful.Container) error {
Produces("application/json", "charset=utf-8"). Produces("application/json", "charset=utf-8").
Doc("Jenkinsfile to Json."). Doc("Jenkinsfile to Json.").
Reads(devops.ReqJenkinsfile{}). Reads(devops.ReqJenkinsfile{}).
Returns(http.StatusOK, RespOK,devops.ResJson{}). Returns(http.StatusOK, RespOK, devops.ResJson{}).
Writes(devops.ResJson{})) Writes(devops.ResJson{}))
// match /git/notifyCommit/?url= // match /git/notifyCommit/?url=
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
) )
var ( var (
jenkinsClientOnce sync.Once jenkinsInitMutex sync.Mutex
jenkinsClient *gojenkins.Jenkins jenkinsClient *gojenkins.Jenkins
jenkinsAdminAddress string jenkinsAdminAddress string
jenkinsAdminUsername string jenkinsAdminUsername string
...@@ -41,35 +41,36 @@ func init() { ...@@ -41,35 +41,36 @@ func init() {
} }
func Client() *gojenkins.Jenkins { func Client() *gojenkins.Jenkins {
jenkinsClientOnce.Do(func() { if jenkinsClient == nil {
jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword) jenkinsInitMutex.Lock()
jenkins, err := jenkins.Init() defer jenkinsInitMutex.Unlock()
if err != nil { if jenkinsClient == nil {
glog.Error("failed to connect jenkins") jenkins := gojenkins.CreateJenkins(nil, jenkinsAdminAddress, jenkinsMaxConn, jenkinsAdminUsername, jenkinsAdminPassword)
return jenkins, err := jenkins.Init()
} if err != nil {
jenkinsClient = jenkins glog.Errorf("failed to connect jenkins, %+v", err)
globalRole, err := jenkins.GetGlobalRole(JenkinsAllUserRoleName) }
if err != nil { globalRole, err := jenkins.GetGlobalRole(JenkinsAllUserRoleName)
glog.Error("failed to get jenkins role") if err != nil {
} glog.Errorf("failed to get jenkins role, %+v", err)
if globalRole == nil { }
_, err := jenkins.AddGlobalRole(JenkinsAllUserRoleName, gojenkins.GlobalPermissionIds{ if globalRole == nil {
GlobalRead: true, _, 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) }, true)
if err != nil { if err != nil {
glog.Error("failed to create jenkins global role") glog.Errorf("failed to create jenkins project role, %+v", err)
return
} }
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 return jenkinsClient
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册