Skip to content

Commit 56bd07e

Browse files
authored
Minor jenkins tests improvements (#181)
* Add timeout to jenkins.waitForBuildToFinish() * Sync argocd commands execution * Further increase timeouts for jenkins jobs.
1 parent bc690d2 commit 56bd07e

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

src/apis/ci/jenkins.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,27 @@ export class JenkinsCI extends Utils {
148148
}
149149

150150
// waitForBuildToFinish waits for a build to finish and get its result
151-
public async waitForBuildToFinish(jobName: string, buildNumber: number) {
151+
public async waitForBuildToFinish(jobName: string, buildNumber: number, timeoutMs: number) {
152152
const url = `${this.jenkinsUrl}/job/${jobName}/${buildNumber}/api/json`;
153153

154-
while (true) {
154+
const retryInterval = 10 * 1000;
155+
let totalTimeMs = 0;
156+
157+
while (timeoutMs === 0 || totalTimeMs < timeoutMs) {
155158
try {
156159
const response = await this.axiosInstance.post(url);
157160
if (response.data.building) {
158-
console.log(`Build #${buildNumber} is still in progress...`);
161+
console.log(`Build #${buildNumber} of job ${jobName} is still in progress...`);
159162
await new Promise(resolve => setTimeout(resolve, 15000)); // Wait for 15 seconds
160163
} else {
161164
console.log(`Build #${buildNumber} finished with status: ${response.data.result}`);
162165
return response.data.result;
163166
}
164167
} catch (error) {
165168
console.error('Error checking build status:', error);
166-
return null;
169+
await new Promise(resolve => setTimeout(resolve, 15000)); // Wait for 15 seconds
167170
}
171+
totalTimeMs += retryInterval;
168172
}
169173
}
170174

src/utils/argocd.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,23 @@ export const syncArgoApplication = async (namespace: string, applicationName: st
3737
`;
3838

3939
// Execute the shell script commands
40-
exec(scriptCommands, (error, stdout: any, stderr: any) => {
41-
if (error) {
42-
console.error(`Error executing commands: ${error.message}`);
43-
return;
44-
}
45-
if (stderr) {
46-
console.error(`Commands STDERR: ${stderr}`);
47-
return;
48-
}
49-
50-
console.log(`succesfully synced application ${applicationName} in cluster`);
51-
console.log(stdout)
52-
});
40+
try {
41+
await new Promise<void>((done, failed) => {
42+
exec(scriptCommands, (error, stdout: any, stderr: any) => {
43+
if (error) {
44+
console.error(`Error executing commands: ${error.message}`);
45+
failed(error);
46+
}
47+
if (stderr) {
48+
console.error(`Commands STDERR: ${stderr}`);
49+
}
50+
51+
console.log(`succesfully synced application ${applicationName} in cluster`);
52+
console.log(stdout);
53+
done()
54+
});
55+
})
56+
} catch (error) {
57+
fail(error)
58+
}
5359
}

tests/gpts/github/test-config/github_suite_jenkins.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { syncArgoApplication } from '../../../../src/utils/argocd';
2121
*/
2222
export const gitHubJenkinsBasicGoldenPathTemplateTests = (gptTemplate: string, stringOnRoute: string) => {
2323
describe(`Red Hat Trusted Application Pipeline ${gptTemplate} GPT tests GitHub provider with public/private image registry`, () => {
24-
jest.retryTimes(2);
2524

2625
const componentRootNamespace = process.env.APPLICATION_ROOT_NAMESPACE || 'rhtap-app';
2726
const developmentNamespace = `${componentRootNamespace}-development`;
@@ -144,10 +143,10 @@ export const gitHubJenkinsBasicGoldenPathTemplateTests = (gptTemplate: string, s
144143
await jenkinsClient.buildJenkinsJob(repositoryName);
145144
console.log('Waiting for the build to start...');
146145
await new Promise(resolve => setTimeout(resolve, 5000));
147-
const jobStatus = await jenkinsClient.waitForBuildToFinish(repositoryName, 1);
146+
const jobStatus = await jenkinsClient.waitForBuildToFinish(repositoryName, 1, 540000);
148147
expect(jobStatus).not.toBe(undefined);
149148
expect(jobStatus).toBe("SUCCESS");
150-
}, 240000);
149+
}, 600000);
151150

152151
/**
153152
* Creates an empty commit
@@ -165,10 +164,10 @@ export const gitHubJenkinsBasicGoldenPathTemplateTests = (gptTemplate: string, s
165164
await jenkinsClient.buildJenkinsJob(repositoryName);
166165
console.log('Waiting for the build to start...');
167166
await new Promise(resolve => setTimeout(resolve, 5000));
168-
const jobStatus = await jenkinsClient.waitForBuildToFinish(repositoryName, 2);
167+
const jobStatus = await jenkinsClient.waitForBuildToFinish(repositoryName, 2, 540000);
169168
expect(jobStatus).not.toBe(undefined);
170169
expect(jobStatus).toBe("SUCCESS");
171-
}, 240000);
170+
}, 600000);
172171

173172
/**
174173
* Obtain the openshift Route for the component and verify that the previous builded image was synced in the cluster and deployed in development environment

tests/gpts/gitlab/suites-config/gitlab_suite_jenkins.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { JenkinsCI } from "../../../../src/apis/ci/jenkins";
2323
*/
2424
export const gitLabJenkinsBasicTests = (softwareTemplateName: string, stringOnRoute: string) => {
2525
describe(`Red Hat Trusted Application Pipeline ${softwareTemplateName} GPT tests GitLab provider with public/private image registry`, () => {
26-
jest.retryTimes(2);
2726

2827
let backstageClient: DeveloperHubClient;
2928
let developerHubTask: TaskIdReponse;
@@ -134,8 +133,8 @@ export const gitLabJenkinsBasicTests = (softwareTemplateName: string, stringOnRo
134133
await jenkinsClient.buildJenkinsJob(repositoryName);
135134
console.log('Waiting for the build to start...');
136135
await new Promise(resolve => setTimeout(resolve, 5000));
137-
await jenkinsClient.waitForBuildToFinish(repositoryName, 1);
138-
}, 240000);
136+
await jenkinsClient.waitForBuildToFinish(repositoryName, 1, 540000);
137+
}, 600000);
139138

140139

141140
/**
@@ -152,8 +151,8 @@ export const gitLabJenkinsBasicTests = (softwareTemplateName: string, stringOnRo
152151
await jenkinsClient.buildJenkinsJob(repositoryName);
153152
console.log('Waiting for the build to start...');
154153
await new Promise(resolve => setTimeout(resolve, 5000));
155-
await jenkinsClient.waitForBuildToFinish(repositoryName, 2);
156-
}, 240000);
154+
await jenkinsClient.waitForBuildToFinish(repositoryName, 2, 540000);
155+
}, 600000);
157156

158157
/**
159158
* Obtain the openshift Route for the component and verify that the previous builded image was synced in the cluster and deployed in development environment

0 commit comments

Comments
 (0)