提交 ff7811d9 编写于 作者: C colynn

feature: the namespace of jenkins agent get from variable

上级 9e29b278
......@@ -159,9 +159,9 @@ func (pm *PipelineManager) CreateBuildJob(creator string, projectID, publishID i
log.Log.Error("getCIConfig occur error: %s", err.Error())
return 0, "", err
}
if len(CIInfo) != 4 {
log.Log.Error("get ci config len is not 4, ciinfo: %+v", CIInfo)
return 0, "", fmt.Errorf("get ci config len is not 4, ciinfo: %+v", CIInfo)
if len(CIInfo) != 5 {
log.Log.Error("get ci config len is not 5, ciinfo: %+v", CIInfo)
return 0, "", fmt.Errorf("get ci config len is not 5, ciinfo: %+v", CIInfo)
}
addr, user, token := CIInfo[0], CIInfo[1], CIInfo[2]
......@@ -390,16 +390,11 @@ func (pm *PipelineManager) CreateBuildJob(creator string, projectID, publishID i
// }
flowProcessor := &jenkins.CIContext{
RegistryAddr: deployInfo[1],
// TODO: add env vars
// TODO: add container templates
EnvVars: envVars,
ContainerTemplates: containerTemplates,
Stages: pipelineStagesStr,
CommonContext: jenkins.CommonContext{
JenkinsSlaveWorkspace: CIInfo[3],
AccessToken: adminToken,
AtomCIServer: atomciServer,
Namespace: CIInfo[4],
},
CallBack: jenkins.CallbackRequest{
Token: adminToken,
......@@ -431,7 +426,6 @@ func (pm *PipelineManager) CreateDeployJob(creator string, projectID, publishID
// Aggregate the app parms for deploy based on request params
appsAllParams, _ := pm.aggregateAppsParamsForDeploy(publishID, stageJSON.StageID, apps, stageJSON)
// TODO: jenkins
CIInfo, err := pm.GetCIConfig(stageJSON.StageID)
if err != nil {
log.Log.Error("getCIConfig occur error: %s", err.Error())
......@@ -546,9 +540,7 @@ func (pm *PipelineManager) CreateDeployJob(creator string, projectID, publishID
Body: callBackRequestBody,
},
CommonContext: jenkins.CommonContext{
JenkinsSlaveWorkspace: CIInfo[3],
AccessToken: adminToken,
AtomCIServer: atomciServer,
Namespace: CIInfo[4],
},
}
......@@ -1180,11 +1172,15 @@ func (pm *PipelineManager) GetCIConfig(stageID int64) ([]string, error) {
if settingItem.Type != "jenkins" {
return []string{}, fmt.Errorf("settings type is: %s, current ci server only support jenkins", settingItem.Type)
}
var url, user, token, workSpace string
var url, user, token, namespace, workSpace string
if jenkinsConfig, ok := settingItem.Config.(*settings.JenkinsConfig); ok {
url = jenkinsConfig.URL
user = jenkinsConfig.User
token = jenkinsConfig.Token
namespace = jenkinsConfig.Namespace
if namespace == "" {
namespace = "devops"
}
workSpace = jenkinsConfig.WorkSpace
} else {
log.Log.Error("parse jenkins config error")
......@@ -1194,7 +1190,7 @@ func (pm *PipelineManager) GetCIConfig(stageID int64) ([]string, error) {
if url == "" || user == "" || token == "" || workSpace == "" {
return nil, fmt.Errorf("请联系管理员确认 系统管理-服务集成 %v 的配置, 当前配置为: url: %v, user: %v, token: %v, workSpace: %v", settingItem.Name, url, user, token, workSpace)
}
return []string{url, user, token, workSpace}, nil
return []string{url, user, token, workSpace, namespace}, nil
}
// getDeployInfo cluster,harbor auth info,arrangeEnv
......
......@@ -92,6 +92,7 @@ type HarborConfig struct {
type JenkinsConfig struct {
BaseConfig
Token string `json:"token,omitempty"`
Namespace string `json:"namespace,omitempty"`
WorkSpace string `json:"workspace,omitempty"`
}
......
......@@ -37,7 +37,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/ghodss/yaml v1.0.0
github.com/go-atomci/go-scm v1.13.2-0.20210629010829-147be8a9bdd3
github.com/go-atomci/workflow v0.0.0-20211028035117-5255a97315b2
github.com/go-atomci/workflow v0.0.0-20211126090842-208f180b47ab
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/go-cmp v0.5.5 // indirect
......
......@@ -200,6 +200,8 @@ github.com/go-atomci/go-scm v1.13.2-0.20210629010829-147be8a9bdd3 h1:mBv4enC3OLi
github.com/go-atomci/go-scm v1.13.2-0.20210629010829-147be8a9bdd3/go.mod h1:f6hTOQHcpcnXNU84YiYywndV7gnP9plkgFU2bl1UkdU=
github.com/go-atomci/workflow v0.0.0-20211028035117-5255a97315b2 h1:z/DDX3yXnMUv+/tWtZDanynRv1m+1V/d4wsCBFdZULs=
github.com/go-atomci/workflow v0.0.0-20211028035117-5255a97315b2/go.mod h1:U396Nlydy0L3cVrlkdqp2DLn8e4DtwN+wJ+nmWIaS0s=
github.com/go-atomci/workflow v0.0.0-20211126090842-208f180b47ab h1:0NUR9i9gCzvDpDh2J9Ytb5uoPpigs4ZqM6v/VFVhzzo=
github.com/go-atomci/workflow v0.0.0-20211126090842-208f180b47ab/go.mod h1:U396Nlydy0L3cVrlkdqp2DLn8e4DtwN+wJ+nmWIaS0s=
github.com/go-bindata/go-bindata v3.1.1+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
......
......@@ -20,10 +20,7 @@ import "github.com/go-atomci/workflow"
// CommonContext ..
type CommonContext struct {
JenkinsSlaveWorkspace string
AccessToken string
RepoCnf string
AtomCIServer string
Namespace string
}
// CallbackRequest ..
......@@ -58,9 +55,6 @@ type ContainerEnv struct {
// CIContext ..
type CIContext struct {
CommonContext
RegistryAddr string
DockerConfig string
DockerAuth string
Stages string
EnvVars []EnvItem
ContainerTemplates []ContainerEnv
......
......@@ -26,7 +26,7 @@ pipeline {
apiVersion: v1
kind: Pod
metadata:
namespace: devops
namespace: {{ .Namespace }}
spec:
containers:
{{- range $i, $item := .ContainerTemplates }}
......
......@@ -26,7 +26,7 @@ pipeline {
apiVersion: v1
kind: Pod
metadata:
namespace: devops
namespace: {{ .Namespace }}
spec:
containers:
{{- range $i, $item := .ContainerTemplates }}
......
......@@ -2,12 +2,6 @@
github.com/Azure/go-ntlmssp
# github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
github.com/Knetic/govaluate
# github.com/Masterminds/goutils v1.1.1
## explicit
# github.com/Masterminds/semver v1.5.0
## explicit
# github.com/Masterminds/sprig v2.22.0+incompatible
## explicit
# github.com/astaxie/beego v1.12.0
## explicit
github.com/astaxie/beego
......@@ -58,7 +52,7 @@ github.com/go-atomci/go-scm/scm/driver/gitlab
github.com/go-atomci/go-scm/scm/driver/internal/hmac
github.com/go-atomci/go-scm/scm/driver/internal/null
github.com/go-atomci/go-scm/scm/transport
# github.com/go-atomci/workflow v0.0.0-20211028035117-5255a97315b2
# github.com/go-atomci/workflow v0.0.0-20211126090842-208f180b47ab
## explicit
github.com/go-atomci/workflow
github.com/go-atomci/workflow/jenkins
......@@ -94,8 +88,6 @@ github.com/googleapis/gnostic/extensions
# github.com/gorilla/websocket v1.4.2
## explicit
github.com/gorilla/websocket
# github.com/huandu/xstrings v1.3.2
## explicit
# github.com/imdario/mergo v0.3.5
github.com/imdario/mergo
# github.com/inconshreveable/mousetrap v1.0.0
......@@ -106,8 +98,6 @@ github.com/isbrick/http-client
github.com/json-iterator/go
# github.com/kr/text v0.2.0
## explicit
# github.com/mitchellh/copystructure v1.2.0
## explicit
# github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/concurrent
# github.com/modern-go/reflect2 v1.0.1
......@@ -370,8 +360,6 @@ k8s.io/client-go/util/exec
k8s.io/client-go/util/flowcontrol
k8s.io/client-go/util/homedir
k8s.io/client-go/util/keyutil
# k8s.io/helm v2.17.0+incompatible => k8s.io/helm v2.11.0+incompatible
## explicit
# k8s.io/klog v1.0.0
k8s.io/klog
# k8s.io/kubernetes v0.0.0-00010101000000-000000000000 => k8s.io/kubernetes v1.17.0
......
......@@ -40,17 +40,22 @@
<el-input v-model.trim="form.config.url" auto-complete="off" placeholder="请输入, 如http://jenkins.example.com"></el-input>
</el-form-item>
<el-form-item label="Jenkins 用户名" prop="config.user" class="form-item">
<el-form-item label="用户名" prop="config.user" class="form-item">
<el-input v-model.trim="form.config.user" auto-complete="off" maxlength="60" placeholder="请输入Jeknins 用户名"></el-input>
</el-form-item>
<el-form-item label="Jenkins 用户Token" prop="config.token" class="form-item">
<el-form-item label="用户Token" prop="config.token" class="form-item">
<el-input v-model.trim="form.config.token" auto-complete="off" maxlength="120" placeholder="请输入Jeknins 用户Token"></el-input>
</el-form-item>
<el-form-item label="Jenkins WorkSpace" prop="config.workspace" class="form-item">
<el-input v-model.trim="form.config.workspace" auto-complete="off" maxlength="120" placeholder="请输入Jeknins workspace"></el-input>
<el-form-item label="工作目录" prop="config.workspace" class="form-item" title="默认是 /home/jenkins/agent">
<el-input v-model.trim="form.config.workspace" auto-complete="off" maxlength="120" placeholder="请输入agent的工作目录,默认是 /home/jenkins/agent"></el-input>
</el-form-item>
<el-form-item label="agent 命名空间" prop="config.namespace" class="form-item" title="请输入配置的jenkins agent运行的命名空间,参照'jenkins配置'默认是devops">
<el-input v-model.trim="form.config.namespace" auto-complete="off" maxlength="120" placeholder="请输入配置的jenkins agent的namespace,默认是devops"></el-input>
</el-form-item>
</div >
<div v-else-if="form.type ==='harbor'">
<el-form-item label="Harbor URL" prop="config.url" class="form-item">
......@@ -206,6 +211,14 @@ export default {
Message.success(this.$t('bm.add.optionSuc'));
this.dialogFormVisible = false;
};
if (this.form.type === "jenkins") {
if (this.form.config.workspace === undefined || this.form.config.workspace === "") {
this.form.config.workspace = "/home/jenkins/agent"
}
if (this.form.config.namespace === undefined || this.form.config.namespace === "") {
this.form.config.namespace = "devops"
}
}
const cl = {
name: this.form.name,
config: this.form.config,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册