{"id":15063075,"url":"https://github.com/jenkins-zh/jenkins-client","last_synced_at":"2025-04-04T21:10:15.363Z","repository":{"id":43053696,"uuid":"397440175","full_name":"jenkins-zh/jenkins-client","owner":"jenkins-zh","description":"The Jenkins client was written by Golang","archived":false,"fork":false,"pushed_at":"2024-12-10T08:39:09.000Z","size":129,"stargazers_count":25,"open_issues_count":6,"forks_count":18,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T20:11:13.378Z","etag":null,"topics":["client","hacktoberfest","jenkins","jenkins-client"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jenkins-zh.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-18T01:44:36.000Z","updated_at":"2025-03-25T07:10:15.000Z","dependencies_parsed_at":"2025-02-28T16:12:15.220Z","dependency_job_id":"c15a3c8c-625a-4af1-b108-82ef7fa723f5","html_url":"https://github.com/jenkins-zh/jenkins-client","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkins-zh%2Fjenkins-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkins-zh%2Fjenkins-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkins-zh%2Fjenkins-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenkins-zh%2Fjenkins-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenkins-zh","download_url":"https://codeload.github.com/jenkins-zh/jenkins-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249532,"owners_count":20908212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","hacktoberfest","jenkins","jenkins-client"],"created_at":"2024-09-24T23:50:54.202Z","updated_at":"2025-04-04T21:10:15.334Z","avatar_url":"https://github.com/jenkins-zh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jcli-client 文档\n\n## 如何安装\n\ngo.mod\n\n```\nrequire github.com/jenkins-zh/jenkins-client\n```\n\n## 配置\n\njcli配置详情\n\n```\n- name: dev\n  url: http://192.168.1.10\n  username: admin\n  token: 11132c9ae4b20edbe56ac3e09cb5a3c8c2\n  proxy: http://192.168.10.10:47586\n  proxyAuth: username:password\n```\n\n所以当你想使用jcli-client，你需要配置一下jenkins.yml，并解析\n\n```\ntype Config struct {\n\tURL      string `yaml:\"url\"`\n\tUserName string `yaml:\"username\"`\n\tToken    string `yaml:\"token\"`\n}\n\nfunc GetJenkinsCore() (core client.JenkinsCore, e error) {\n\t// 读取配置文件\n\tjenkinsConfigPath := \"./jenkins.yml\"\n\tyamlFile, e := ioutil.ReadFile(jenkinsConfigPath)\n\tif e != nil {\n\t\treturn\n\t}\n\t// yaml解析\n\tvar config Config\n\te = yaml.Unmarshal(yamlFile, \u0026config)\n\tif e != nil {\n\t\treturn\n\t}\n\t// 封装JenkinsCore\n\tcore = client.JenkinsCore{\n\t\tURL:      config.URL,\n\t\tUserName: config.UserName,\n\t\tToken:    config.Token,\n\t}\n\tcrumbIssuer, e := core.GetCrumb()\n\tif e != nil {\n\t\treturn\n\t} else if crumbIssuer != nil {\n\t\tcore.JenkinsCrumb = *crumbIssuer\n\t}\n\treturn\n}\n```\n\n## Job API\n\n常用API\n\n```\n// GetBuild get build information of a job\nfunc (q *JobClient) GetBuild(jobName string, id int) (job *JobBuild, err error){...}\n\n// Build trigger a job\nfunc (q *JobClient) Build(jobName string) (err error) {...}\n\n// BuildWithParams build a job which has params\nfunc (q *JobClient) BuildWithParams(jobName string, parameters []ParameterDefinition) (err error) {...}\n\n// GetHistory returns the build history of a job\nfunc (q *JobClient) GetHistory(name string) (builds []*JobBuild, err error) {...}\n\n// Log get the log of a job\nfunc (q *JobClient) Log(jobName string, history int, start int64) (jobLog JobLog, err error){...}\n```\n\n## User API\n\n常用API\n\n```\n// Create will create a user in Jenkins\nfunc (q *UserClient) Create(username, password string) (user *UserForCreate, err error) {...}\n\n// Delete will remove a user from Jenkins\nfunc (q *UserClient) Delete(username string) (err error) {...}\n```\n\n## 调用案例\n\n```\ntype JobBuildOptions struct {\n\tEnv       string \n\tJobName   string \n\tBranchTag string \n}\n\n\nfunc BuildJob(jobBuild JobBuildOptions) (e error) {\n\tcore, e := GetJenkinsCore()\n\tjobClient = client.JobClient{core}\n\tif e != nil {\n\t\treturn\n\t}\n\tparam1 := client.ParameterDefinition{\n\t\tDescription:           \"pre 和 prd 环境使用 tag 发布\",\n\t\tName:                  \"BRANCH_TAG\",\n\t\tType:                  \"Branch or Tag\",\n\t\tValue:                 jobBuild.BranchTag,\n\t\tDefaultParameterValue: client.DefaultParameterValue{Value: \"origin/master\"},\n\t}\n\tparam2 := client.ParameterDefinition{\n\t\tDescription:           \"环境选择\",\n\t\tName:                  \"ENV\",\n\t\tType:                  \"Choice Parameter\",\n\t\tValue:                 jobBuild.Env,\n\t\tDefaultParameterValue: client.DefaultParameterValue{Value: \"qa\"},\n\t}\n\tparam3 := client.ParameterDefinition{\n\t\tDescription:           \"部署Type\",\n\t\tName:                  \"DEPLOY_TYPE\",\n\t\tType:                  \"Choice Parameter\",\n\t\tValue:                 \"publish\",\n\t\tDefaultParameterValue: client.DefaultParameterValue{Value: \"publish\"},\n\t}\n\tparams := []client.ParameterDefinition{param1, param2, param3}\n\te = jobClient.BuildWithParams(jobBuild.JobName, params)\n\treturn\n}\n```\n\n## 插件依赖\n\n本 Jenkins 客户端的部分 API 需要依赖特定的插件，请参考下面的列表：\n\n| API | Plugin |\n|---|---|\n| Search Job | [pipeline-restful-api](https://github.com/jenkinsci/pipeline-restful-api-plugin) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenkins-zh%2Fjenkins-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenkins-zh%2Fjenkins-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenkins-zh%2Fjenkins-client/lists"}