Skip to content
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

Getting the VSTS_HTTP_RETRY option correctly. Setting to zero will di… #9216

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ export class JenkinsRestClient {
const jobName = tl.getInput("jobName", true);
const strictSSL: boolean = ('true' !== tl.getEndpointDataParameter(endpoint, 'acceptUntrustedCerts', true));
const jobUrlInfix = JenkinsJobDetails.GetJobUrlInfix(jobName);
const retryLimit = parseInt(tl.getVariable("VSTS_HTTP_RETRY")) ? parseInt(tl.getVariable("VSTS_HTTP_RETRY")) : 4;

const retryLimitValue: string = tl.getVariable("VSTS_HTTP_RETRY");
const retryLimit: number = (!!retryLimitValue && !isNaN(parseInt(retryLimitValue))) ? parseInt(retryLimitValue) : 4;
tl.debug(`RetryLimit set to ${retryLimit}`);

let requestUrl: string = `${endpointUrl}${jobUrlInfix}/${urlPath}`;
console.log(tl.loc("DownloadingContentFromJenkinsServer", requestUrl, strictSSL));
Expand Down
3 changes: 3 additions & 0 deletions Tasks/JenkinsDownloadArtifactsV1/Tests/JenkinsTestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export interface ExpectedResult {

export function RegisterHttpClientMock(tr: tmrm.TaskMockRunner, getResultCallback: any)
{
// setting retry value to zero as we don't want the test to hang up
process.env['VSTS_HTTP_RETRY'] = "0"

tr.registerMock("artifact-engine/Providers/typed-rest-client/HttpClient", {
HttpClient: function(name, handlers, options) {
return {
Expand Down
19 changes: 19 additions & 0 deletions Tasks/JenkinsDownloadArtifactsV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,23 @@ describe('JenkinsDownloadArtifacts L0 Suite', function () {
done(err);
}
});

it('Should retry if JenkinsClient encounters an error', (done) => {
const tp: string = path.join(__dirname, 'L0ShouldRetryCorrectlyWhenErrorHappens.js');
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

try {
tr.run();

let expectedMessage: string = "RetryingOperation DownloadJsonContent 1";
assert(tr.stdout.indexOf(expectedMessage) != -1, tr.stdout);

done();
} catch(err) {
console.log(tr.stdout);
console.log(tr.stderr);
console.log(err);
done(err);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import tmrm = require('vsts-task-lib/mock-run');
import path = require('path');
import helper = require("./JenkinsTestHelper");

const taskPath = path.join(__dirname, '..', 'jenkinsdownloadartifacts.js');
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tr.setInput("serverEndpoint", "ID1");
tr.setInput("jobName", "myfreestyleproject")
tr.setInput("saveTo", "jenkinsArtifacts");
tr.setInput("filePath", "/");
tr.setInput("jenkinsBuild", "BuildNumber");
tr.setInput("jenkinsBuildNumber", "10");
tr.setInput("itemPattern", "**");
tr.setInput("downloadCommitsAndWorkItems", "false");

process.env['ENDPOINT_URL_ID1'] = 'http://url';
process.env['ENDPOINT_AUTH_PARAMETER_connection1_username'] = 'dummyusername';
process.env['ENDPOINT_AUTH_PARAMETER_connection1_password'] = 'dummypassword';
process.env['ENDPOINT_DATA_ID1_acceptUntrustedCerts'] = 'true';

helper.RegisterArtifactEngineMock(tr);
helper.RegisterHttpClientMock(tr, (url: string) => {
});

process.env['VSTS_HTTP_RETRY'] = "1";
tr.run();