未验证 提交 e4f091bb 编写于 作者: Z Zhao Xiaojie 提交者: GitHub

Merge pull request #29 from LinuxSuRen/fix/get-crumb-err

Fix the error when no crumb set
......@@ -46,7 +46,6 @@ var jobBuildCmd = &cobra.Command{
paramDefs := []client.ParameterDefinition{}
hasParam := false
if job, err := jclient.GetJob(jobOption.Name); err == nil {
fmt.Println(job.Property)
if len(job.Property) != 0 {
for _, pro := range job.Property {
if len(pro.ParameterDefinitions) == 0 {
......
......@@ -51,7 +51,8 @@ func (j *JenkinsCore) AuthHandle(request *http.Request) {
}
func (j *JenkinsCore) CrumbHandle(request *http.Request) error {
if c, err := j.GetCrumb(); err == nil {
if c, err := j.GetCrumb(); err == nil && c != nil {
// cannot get the crumb could be a noraml situation
j.CrumbRequestField = c.CrumbRequestField
j.Crumb = c.Crumb
request.Header.Add(j.CrumbRequestField, j.Crumb)
......@@ -80,7 +81,10 @@ func (j *JenkinsCore) GetCrumb() (*JenkinsCrumb, error) {
if data, err := ioutil.ReadAll(response.Body); err == nil {
if response.StatusCode == 200 {
json.Unmarshal(data, &crumbIssuer)
} else if response.StatusCode == 404 {
return nil, err
} else {
log.Printf("Unexpected status code: %d.", response.StatusCode)
return nil, err
}
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册