-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Submitting a job and waiting until it completes? #102
Comments
There is no builtin function, but you can submit the job, get the build id (see #30 (comment)), and then query the job until it finishes. |
Hey, @rayterrill. Did you implement the solution that @silas suggested? Could you please share it here? I'm currently trying to do the same thing. Actually, I'm struggling with it so far. Many thanks. |
@marisaroque Something like this should work: const jenkins = require('jenkins')({
baseUrl: 'http://admin:admin@localhost:8080',
crumbIssuer: true,
promisify: true,
});
async function main() {
const jobName = 'test';
const queueId = await jenkins.job.build(jobName);
let queueItem;
while (true) {
queueItem = await jenkins.queue.item(queueId);
if (queueItem.executable) {
break;
}
if (queueItem.cancelled) {
console.log('queue cancelled');
return;
}
console.log('waiting on queue...');
await new Promise(r => setTimeout(r, 1000));
}
let job;
while (true) {
job = await jenkins.build.get(jobName, queueItem.executable.number);
if (!job.building) {
break;
}
console.log('waiting on job...');
await new Promise(r => setTimeout(r, 1000));
}
console.log(job.fullDisplayName, job.result);
}
main(); |
Perfect, @silas! It works like a charm and really helped a lot. Thank you. 🙂 |
@silas Just stumbling upon this issue. Thanks for posting that code snippet above--it really helps. However, am I correct that it's missing code that would handle a possible build failure? 🤔 |
@markcellus I guess it depends on what you definition of complete it. it's suppose to poll until it's not building anymore. You can look at the state of |
Oh ok that makes sense. So I'm guessing I can't use the |
This is a pretty light wrapper around the jenkins api, err is basically just an unexpected status code from the api build endpoint, a network error, or invalid input. An error from |
Is there a mechanism to support submitting a job and waiting for it to complete or chaining the calls together to allow for this functionality? Cheers for this module @silas this is super helpful.
The text was updated successfully, but these errors were encountered: