bndr / gojenkins

Jenkins API Client in Go. Looking for maintainers to move this project forward.
Apache License 2.0
870 stars 446 forks source link

`GetBuild` return nothing without any error, but the job has finnished success. #213

Open rickyxucn opened 4 years ago

rickyxucn commented 4 years ago

I found a case, GetBuild return nothing without any error, but the job has finnished success.

Code:

func main() {
    jenkins, _ := gojenkins.CreateJenkins(nil,
        "xxx",
        "xxx",
        "xxx").Init()
    build, _ := jenkins.GetBuild("shopee-foody-account-test", 162)
    fmt.Println(*build.Raw)
}

Output:

{[] [] false  {[]  []} [] [] <nil> 0 0 <nil>    false 0 0  0  <nil>  [] []}

But, when I run curl as follows:

curl https://xxx/job/xxx/162/api/json

Output:

{
    "_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
    "actions": [],
    "artifacts": [],
    "building": false,
    "description": null,
    "displayName": "xxx",
    "duration": 102753,
    "estimatedDuration": 103631,
    "executor": null,
    "fullDisplayName": "xxx",
    "id": "162",
    "keepLog": false,
    "number": 162,
    "queueId": 240655,
    "result": "SUCCESS",
    "timestamp": 1596195642480,
    "url": "https://xxx/job/xxx/162/",
    "changeSets": [],
    "culprits": [],
    "nextBuild": null,
    "previousBuild": {}
}
WHBANG commented 4 years ago

hahahha

SwenChan commented 4 years ago

Cuz this build is still "Preparing", I have met this before and I write a for loop to check if I can continue

for checkBuildStatus(n+1, job) {
        time.Sleep(1 * time.Second)
        log.Printf("wait for done: %d\n", n+1)
    }
func checkBuildStatus(n int64, job *gojenkins.Job) bool {
    buildResult, _ := job.GetBuild(n)
    return buildResult == nil
}
rickyxucn commented 4 years ago

Cuz this build is still "Preparing", I have met this before and I write a for loop to check if I can continue

for checkBuildStatus(n+1, job) {
      time.Sleep(1 * time.Second)
      log.Printf("wait for done: %d\n", n+1)
  }
func checkBuildStatus(n int64, job *gojenkins.Job) bool {
  buildResult, _ := job.GetBuild(n)
  return buildResult == nil
}

In my case, the build has success and I can get it's status by RESTful API.

hengren108 commented 3 years ago

I also encountered the same problem, did you solve it @rickyxucn

rickyxucn commented 3 years ago

I also encountered the same problem, did you solve it @rickyxucn

Not yet. I implement this method through RESTful API and I have not encountered this problem again.

charlseo commented 3 years ago

experiencing the same.