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

jenkins init

Signed-off-by: Nrunzexia <runzexia@yunify.com>
上级 ac961011
......@@ -590,7 +590,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 /pipeline-model-converter/toJenkinsfile
......@@ -601,7 +601,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
......@@ -612,7 +612,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.
先完成此消息的编辑!
想要评论请 注册