cliffano / nestor

Jenkins CLI and node.js client
http://blog.cliffano.com/tag/nestor/
MIT License
182 stars 27 forks source link

[Support] How to start a build and get a callback when it's finished? #47

Closed jakub-g closed 7 years ago

jakub-g commented 7 years ago

Hello, my use case is basically like this:

startBuildAndMonitorItsProgress().then(
  function buildFinishedSuccessfully() {

  }, function buildFailed() {

  });

It seems that I can accomplish it by doing nestor.buildJob, followed by setInterval(nestor.readLatestJob) and reading response.result and response.timestamp and then:

if response.timestamp < myTimestampWhenQueueingTheJob I am getting info about previously completed job so I discard it (and the thing I asked for is still in the queue) else check if response.result !== null then my build is finished, so I call the callback / resolve the promise

but it all seems very hacky

Do you think there's a better way?

Thanks!

Edit: found job.checkStarted which will simplify things a bit

jakub-g commented 7 years ago

FYI I wrote somethin on top of Nestor that is doing the pipeline:

https://github.com/jakub-g/jenkins-build-pipeline/blob/master/lib/jenkins-build-pipeline.js