Skip to content

Commit

Permalink
Fixes for several issues in JenkinsQueueJob task (#8887)
Browse files Browse the repository at this point in the history
* Fixes for #7527, bug in how tree query parameters used, and builds failing when connection is lost while streaming jenkins console.

* added code comment

* changes per Pr comments
  • Loading branch information
keljos authored Nov 21, 2018
1 parent 76ba774 commit d6f5098
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Tasks/JenkinsQueueJobV2/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import tl = require('vsts-task-lib/task');
import fs = require('fs');
import path = require('path');
import url = require('url');
import shell = require('shelljs');
import request = require('request');

import { JobSearch } from './jobsearch';
Expand Down Expand Up @@ -276,7 +275,9 @@ export class Job {
if (thisJob.queue.TaskOptions.capturePipeline) {
const downstreamProjects = thisJob.Search.ParsedTaskBody.downstreamProjects || [];
downstreamProjects.forEach((project) => {
new Job(thisJob.queue, thisJob, project.url, null, -1, project.name); // will add a new child to the tree
if (project.color !== 'disabled') {
new Job(thisJob.queue, thisJob, project.url, null, -1, project.name); // will add a new child to the tree
}
});
}
thisJob.Search.ResolveIfKnown(thisJob); // could change state
Expand Down Expand Up @@ -445,7 +446,7 @@ export class Job {
thisJob.stopWork(0, JobState.Finishing);
}
}
}).auth(thisJob.queue.TaskOptions.username, thisJob.queue.TaskOptions.password, true)
}).auth(thisJob.queue.TaskOptions.username, thisJob.queue.TaskOptions.password, false) //The 'false' flag forces the request to send proper authentication headers when retrying
.on('error', (err) => {
throw err;
});
Expand Down
22 changes: 15 additions & 7 deletions Tasks/JenkinsQueueJobV2/jobsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import tl = require('vsts-task-lib/task');
import fs = require('fs');
import path = require('path');
import shell = require('shelljs');
import url = require('url');
import Q = require('q');
import request = require('request');

Expand Down Expand Up @@ -33,7 +29,7 @@ export class JobSearch {
private foundCauses : any[] = []; // all found causes indexed by executableNumber

public Initialized: boolean = false;
public ParsedTaskBody: {downstreamProjects?: {name: string, url: string}[], lastBuild?: {number: number}}; // the parsed task body of the job definition
public ParsedTaskBody: ParsedTaskBody; // the parsed task body of the job definition
private initialSearchBuildNumber: number = -1; // the intial, most likely build number for child jobs
private nextSearchBuildNumber: number = -1; // the next build number to check
private searchDirection: number = -1; // the direction to search, start by searching backwards
Expand All @@ -45,7 +41,7 @@ export class JobSearch {
const defer: Q.Deferred<void> = Q.defer<void>();
const thisSearch: JobSearch = this;
if (!thisSearch.Initialized) { //only initialize once
const apiTaskUrl: string = util.addUrlSegment(thisSearch.taskUrl, '/api/json?tree=downstreamProjects[name,url],lastBuild[number]');
const apiTaskUrl: string = util.addUrlSegment(thisSearch.taskUrl, '/api/json?tree=downstreamProjects[name,url,color],lastBuild[number]');
tl.debug('getting job task URL:' + apiTaskUrl);
request.get({ url: apiTaskUrl, strictSSL: thisSearch.queue.TaskOptions.strictSSL }, function requestCallBack(err, httpResponse, body) {
if (!thisSearch.Initialized) { // only initialize once
Expand Down Expand Up @@ -242,7 +238,7 @@ export class JobSearch {
thisSearch.stopWork(0); // found everything we were looking for
return;
} else {
const url: string = util.addUrlSegment(thisSearch.taskUrl, thisSearch.nextSearchBuildNumber + '/api/json?tree=actions,timestamp');
const url: string = util.addUrlSegment(thisSearch.taskUrl, thisSearch.nextSearchBuildNumber + '/api/json?tree=actions[causes[shortDescription,upstreamBuild,upstreamProject,upstreamUrl]],timestamp');
tl.debug('pipeline, locating child execution URL:' + url);
request.get({ url: url, strictSSL: thisSearch.queue.TaskOptions.strictSSL }, function requestCallback(err, httpResponse, body) {
tl.debug('locateExecution().requestCallback()');
Expand Down Expand Up @@ -303,3 +299,15 @@ export class JobSearch {
}
}
}

interface Project {
name: string,
url: string,
color: string
}
interface ParsedTaskBody {
downstreamProjects?: Project[],
lastBuild?: {
number: number
}
}
6 changes: 3 additions & 3 deletions Tasks/JenkinsQueueJobV2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Tasks/JenkinsQueueJobV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"demands": [],
"version": {
"Major": 2,
"Minor": 142,
"Patch": 2
"Minor": 144,
"Patch": 0
},
"groups": [
{
Expand Down
2 changes: 1 addition & 1 deletion Tasks/JenkinsQueueJobV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"demands": [],
"version": {
"Major": 2,
"Minor": 142,
"Minor": 144,
"Patch": 0
},
"groups": [
Expand Down

0 comments on commit d6f5098

Please sign in to comment.