Skip to content

Instantly share code, notes, and snippets.

@null511
Last active May 14, 2018 21:55
Show Gist options
  • Save null511/aedd7a1f64fafccb353313142af07f27 to your computer and use it in GitHub Desktop.
Save null511/aedd7a1f64fafccb353313142af07f27 to your computer and use it in GitHub Desktop.
Get build number using Jenkins.NET
// Enqueue a new build and get queue #
JenkinsBuildResult buildResult = client.Jobs.Build(jobName);
int? queueItemNumber = buildResult.GetQueueItemNumber();
// Poll queue item until build number is available
int? buildNumber = null;
while (!buildNumber.HasValue) {
var queueItem = client.Queue.GetItem(queueItemNumber.Value);
buildNumber = queueItem?.Executable?.Number;
if (buildNumber.HasValue) break;
Thread.Sleep(200);
}
return buildNumber.Value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment