marcells / node-build-monitor

A Build Monitor written in Node.js, which supports several build services and can be easily extended.
https://marcells.github.io/node-build-monitor
MIT License
349 stars 168 forks source link

Jenkins - Multibranch Pipeline -> Error on retrieving builds #106

Open yoshgoodman opened 6 years ago

yoshgoodman commented 6 years ago

TypeError: Cannot read property 'slice' of undefined at /build-mon/app/services/Jenkins.js:58:46 at Request._callback (/build-mon/app/services/Jenkins.js:31:17) at Request.self.callback (/build-mon/node_modules/request/request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:194:7) at Request.<anonymous> (/build-mon/node_modules/request/request.js:1163:10) at emitOne (events.js:96:13) at Request.emit (events.js:191:7) at IncomingMessage.<anonymous> (/build-mon/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:293:19)

marcells commented 6 years ago

Multibranch pipelines were not tested.

What Jenkins Server version do you use? I can try to reproduce it, but it could take a while, cause I'm off for serval days.

If you want to, you can also take a look at app/services/Jenkins.js and make a pull request.

yoshgoodman commented 6 years ago

Thanks, @marcells we currently on Jenkins ver. 2.104

I will try to look at app/services/Jenkins.js but I have not had any node experience so don't expect much.

yoshgoodman commented 6 years ago

Hi @marcells been trying to look at app/services/Jenkins.js

Seems as if Multibranch pipelines is a completely new build type.

In requestBuildsForJobByUrl Jenkins is not returning builds but rather jobs

You would need to refactor the whole file going forward. From my side, I don't have the knowledge to do so. So won't be making a PR.

Thanks for the awesome build monitor.

dickschoeller commented 6 years ago

I was using curl to look at the returns from Jenkins with multibranch pipelines. If I give curl a path like https://node/job/my-group/job/my-job/job/master/api/json I get back response that looks like what you get from a traditional job. If you give one of the intermediate job names, like my-job, you get a list of jobs as the original problem statement describes. So, it would seem 2 things ought to be supported.

  1. Specify the top level and recurse in finding recent jobs.
  2. Specify the path to a specific job.

Note that master in the above URL is a specific branch. What I've seen in the Jenkins UI is that since each pull request is potentially on a new branch, the list of branches changes as those come and go. That's why the recursive approach is attractive, you could have a single config which reports on the active branches.

dickschoeller commented 6 years ago

I just found a typo in my own configuration file. So, specifying the path down to the specific branch build works. The only issue would be then, to support recursing from a parent to show recent builds on all of the branches.

marcells commented 6 years ago

Alright. I'll take a look at it, if I find some time.

Do you think something like this would be a good configuration?

job: myjob job: mygroup/myjob job: mygroup/myjob/branch job: mygroup/myjob/* job: mygroup/*

I could then parse the job config with a regex or string split and make the appropriate api calls.

dickschoeller commented 6 years ago

Sounds workable to me.

marcells commented 6 years ago

@dickschoeller or @yoshgoodman Do you want to make the implementation?

It will take some time until I can take a look at it in detail. I also have to setup and configure Jenkins first.

enigmatic commented 6 years ago

@dickschoeller I'm not sure if this works for your case, but I updated my fork by adding a new "jobs" option for a job that contains more jobs

My server is Enterprise version 2.89.4.2 and the jobs are structured: /job/<github organization>/job/<repo>/job/<branch>

Thus my config looks like:

"services": [
    {
      "name": "Jenkins",
      "configuration": {
        "url": "<server>",
        "jobs": "<github organization>/job/<repo>",
        "numberOfBuildsPerJob": 1,
        "options": {
          "strictSSL": false
        }
      }
    }
  ]