Skip to content

Commit 3843dea

Browse files
authored
fix(playwrighttesting): ADO job name from environment variables (Azure#32620)
### Packages impacted by this PR @azure/microsoft-playwright-testing ### Issues associated with this PR ### Describe the problem that is addressed by this PR ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 65c9522 commit 3843dea

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

sdk/playwrighttesting/microsoft-playwright-testing/src/reporter/mptReporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class MPTReporter implements Reporter {
266266
const testResultObject: MPTTestResult = this.reporterUtils.getTestResultObject(
267267
test,
268268
result,
269-
this.ciInfo.jobId!,
269+
this.ciInfo.jobName!,
270270
);
271271
this.testResultBatch.add(testResultObject);
272272
// Store test attachments in array

sdk/playwrighttesting/microsoft-playwright-testing/src/utils/cIInfoProvider.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type CIInfo = {
1717
revisionUrl: string | null;
1818
runId: string | null;
1919
runAttempt: number | null;
20-
jobId: string | null;
20+
jobName: string | null;
2121
};
2222

2323
export class CIInfoProvider {
@@ -52,7 +52,7 @@ export class CIInfoProvider {
5252
runAttempt: process.env["GITHUB_RUN_ATTEMPT"]
5353
? parseInt(process.env["GITHUB_RUN_ATTEMPT"], 10)
5454
: null,
55-
jobId: process.env["GITHUB_JOB"] || null,
55+
jobName: process.env["GITHUB_JOB"] || null,
5656
};
5757
} else if (ciProvider === CI_PROVIDERS.ADO) {
5858
// Logic to get Azure DevOps CIInfo
@@ -69,9 +69,8 @@ export class CIInfoProvider {
6969
runAttempt: process.env["RELEASE_ATTEMPTNUMBER"]
7070
? parseInt(process.env["RELEASE_ATTEMPTNUMBER"], 10)
7171
: parseInt(process.env["SYSTEM_JOBATTEMPT"] ?? "", 10),
72-
jobId: process.env["RELEASE_DEPLOYMENTID"]
73-
? process.env["RELEASE_DEPLOYMENTID"]
74-
: process.env["SYSTEM_JOBID"] || null,
72+
jobName:
73+
process.env["SYSTEM_JOBDISPLAYNAME"] ?? process.env["RELEASE_DEPLOYMENTID"] ?? null,
7574
};
7675
} else {
7776
// Handle unsupported CI provider
@@ -84,7 +83,7 @@ export class CIInfoProvider {
8483
revisionUrl: process.env["REVISION_URL"] ?? null,
8584
runId: process.env["RUN_ID"] ?? null,
8685
runAttempt: process.env["RUN_ATTEMPT"] ? parseInt(process.env["RUN_ATTEMPT"], 10) : null,
87-
jobId: process.env["JOB_ID"] ?? null,
86+
jobName: process.env["JOB_ID"] ?? null,
8887
};
8988
}
9089
}

sdk/playwrighttesting/microsoft-playwright-testing/test/utils/clInfoProvider.spec.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("CIInfoProvider", () => {
3838
expect(ciInfo.revisionUrl).to.equal("https://github.com/repo/commit/sampleSha");
3939
expect(ciInfo.runId).to.equal("runId123");
4040
expect(ciInfo.runAttempt).to.equal(1);
41-
expect(ciInfo.jobId).to.equal("testJob");
41+
expect(ciInfo.jobName).to.equal("testJob");
4242
});
4343

4444
it("should return GitHub CIInfo with null fields when Github environment variables are not set", () => {
@@ -54,7 +54,7 @@ describe("CIInfoProvider", () => {
5454
expect(ciInfo.revisionUrl).to.be.null;
5555
expect(ciInfo.runId).to.be.null;
5656
expect(ciInfo.runAttempt).to.be.null;
57-
expect(ciInfo.jobId).to.be.null;
57+
expect(ciInfo.jobName).to.be.null;
5858
});
5959

6060
it("should return Azure DevOps CIInfo when Azure DevOps environment variables are set", () => {
@@ -72,6 +72,7 @@ describe("CIInfoProvider", () => {
7272
process.env["SYSTEM_DEFINITIONID"] = "def123";
7373
process.env["SYSTEM_JOBATTEMPT"] = "1";
7474
process.env["RELEASE_DEFINITIONID"] = "Rdef123";
75+
process.env["SYSTEM_JOBDISPLAYNAME"] = "jobName123";
7576
process.env["RELEASE_DEPLOYMENTID"] = "Rdep123";
7677

7778
const ciInfo = CIInfoProvider.getCIInfo();
@@ -85,7 +86,37 @@ describe("CIInfoProvider", () => {
8586
"https://dev.azure.com/project123/_git/repo123/commit/commitSha123",
8687
);
8788
expect(ciInfo.runId).to.equal("Rdef123-Rdep123");
88-
expect(ciInfo.jobId).to.equal("Rdep123");
89+
expect(ciInfo.jobName).to.equal("jobName123");
90+
});
91+
92+
it("should return Azure DevOps CIInfo when Azure DevOps environment variables are set (SYSTEM_JOBDISPLAYNAME not set)", () => {
93+
process.env["AZURE_HTTP_USER_AGENT"] = "someAgent";
94+
process.env["TF_BUILD"] = "true";
95+
process.env["BUILD_REPOSITORY_ID"] = "repo123";
96+
process.env["BUILD_SOURCEBRANCH"] = "main";
97+
process.env["BUILD_REQUESTEDFOR"] = "testAuthor";
98+
process.env["BUILD_SOURCEVERSION"] = "commitSha123";
99+
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "https://dev.azure.com/";
100+
process.env["SYSTEM_TEAMPROJECT"] = "project123";
101+
process.env["BUILD_REPOSITORY_NAME"] = "repo123";
102+
process.env["SYSTEM_JOBID"] = "job123";
103+
process.env["SYSTEM_DEFINITIONID"] = "def123";
104+
process.env["SYSTEM_JOBATTEMPT"] = "1";
105+
process.env["RELEASE_DEFINITIONID"] = "Rdef123";
106+
process.env["RELEASE_DEPLOYMENTID"] = "Rdep123";
107+
108+
const ciInfo = CIInfoProvider.getCIInfo();
109+
110+
expect(ciInfo.provider).to.equal(CI_PROVIDERS.ADO);
111+
expect(ciInfo.repo).to.equal("repo123");
112+
expect(ciInfo.branch).to.equal("main");
113+
expect(ciInfo.author).to.equal("testAuthor");
114+
expect(ciInfo.commitId).to.equal("commitSha123");
115+
expect(ciInfo.revisionUrl).to.equal(
116+
"https://dev.azure.com/project123/_git/repo123/commit/commitSha123",
117+
);
118+
expect(ciInfo.runId).to.equal("Rdef123-Rdep123");
119+
expect(ciInfo.jobName).to.equal("Rdep123");
89120
});
90121

91122
it("should return Azure DevOps CIInfo with null fields when Azure DevOps environment variables are not set", () => {
@@ -101,7 +132,7 @@ describe("CIInfoProvider", () => {
101132
expect(ciInfo.commitId).to.be.null;
102133
expect(ciInfo.revisionUrl).to.be.null;
103134
expect(ciInfo.runId).to.be.null;
104-
expect(ciInfo.jobId).to.be.null;
135+
expect(ciInfo.jobName).to.be.null;
105136
});
106137

107138
it("should return default CIInfo when no supported CI environment is detected", () => {
@@ -124,7 +155,7 @@ describe("CIInfoProvider", () => {
124155
expect(ciInfo.revisionUrl).to.equal("https://default.com/repo/commit/defaultCommit");
125156
expect(ciInfo.runId).to.equal("defaultRunId");
126157
expect(ciInfo.runAttempt).to.equal(2);
127-
expect(ciInfo.jobId).to.equal("defaultJobId");
158+
expect(ciInfo.jobName).to.equal("defaultJobId");
128159
});
129160

130161
it("should return default CIInfo with null fields when no supported CI environment is detected", () => {
@@ -138,6 +169,6 @@ describe("CIInfoProvider", () => {
138169
expect(ciInfo.revisionUrl).to.be.null;
139170
expect(ciInfo.runId).to.be.null;
140171
expect(ciInfo.runAttempt).to.be.null;
141-
expect(ciInfo.jobId).to.be.null;
172+
expect(ciInfo.jobName).to.be.null;
142173
});
143174
});

0 commit comments

Comments
 (0)