Skip to content

Commit 2ca76b2

Browse files
committed
add logs to azure pipelines
1 parent c46e06e commit 2ca76b2

File tree

1 file changed

+53
-25
lines changed

1 file changed

+53
-25
lines changed

packages/bundler-plugin-core/src/utils/providers/AzurePipelines.ts

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,78 @@ export function detect(envs: ProviderEnvs): boolean {
1212
return Boolean(envs?.SYSTEM_TEAMFOUNDATIONSERVERURI);
1313
}
1414

15-
function _getBuild(inputs: ProviderUtilInputs): ProviderServiceParams["build"] {
15+
function _getBuild(
16+
inputs: ProviderUtilInputs,
17+
output: Output,
18+
): ProviderServiceParams["build"] {
1619
const { args, envs } = inputs;
1720
if (args?.build && args.build !== "") {
21+
debug(`Using build: ${args.build}`, { enabled: output.debug });
1822
return args.build;
1923
}
20-
return envs?.BUILD_BUILDNUMBER ?? null;
24+
25+
const build = envs?.BUILD_BUILDNUMBER ?? null;
26+
debug(`Using build: ${build}`, { enabled: output.debug });
27+
return build;
2128
}
2229

2330
function _getBuildURL(
2431
inputs: ProviderUtilInputs,
32+
output: Output,
2533
): ProviderServiceParams["buildURL"] {
2634
const { envs } = inputs;
35+
let buildURL: string | null = null;
2736
if (envs?.SYSTEM_TEAMPROJECT && envs?.BUILD_BUILDID) {
28-
return `${envs?.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs?.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs?.BUILD_BUILDID}`;
37+
buildURL = `${envs?.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs?.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs?.BUILD_BUILDID}`;
2938
}
30-
return null;
39+
debug(`Using build URL: ${buildURL}`, { enabled: output.debug });
40+
return buildURL;
3141
}
3242

3343
function _getBranch(
3444
inputs: ProviderUtilInputs,
45+
output: Output,
3546
): ProviderServiceParams["branch"] {
3647
const { args, envs } = inputs;
3748
if (args?.branch && args.branch !== "") {
49+
debug(`Using branch: ${args.branch}`, { enabled: output.debug });
3850
return args.branch;
3951
}
4052

53+
let branch: string | null = null;
4154
if (envs?.BUILD_SOURCEBRANCH) {
42-
return envs?.BUILD_SOURCEBRANCH.toString().replace("refs/heads/", "");
55+
branch = envs?.BUILD_SOURCEBRANCH.toString().replace("refs/heads/", "");
4356
}
4457

45-
return null;
58+
debug(`Using branch: ${branch}`, { enabled: output.debug });
59+
return branch;
4660
}
4761

48-
function _getJob(envs: ProviderEnvs): ProviderServiceParams["job"] {
49-
return envs?.BUILD_BUILDID ?? null;
62+
function _getJob(
63+
envs: ProviderEnvs,
64+
output: Output,
65+
): ProviderServiceParams["job"] {
66+
const job = envs?.BUILD_BUILDID ?? null;
67+
debug(`Using job: ${job}`, { enabled: output.debug });
68+
return job;
5069
}
5170

52-
function _getPR(inputs: ProviderUtilInputs): ProviderServiceParams["pr"] {
71+
function _getPR(
72+
inputs: ProviderUtilInputs,
73+
output: Output,
74+
): ProviderServiceParams["pr"] {
5375
const { args, envs } = inputs;
5476
if (args?.pr && args.pr !== "") {
77+
debug(`Using PR: ${args.pr}`, { enabled: output.debug });
5578
return args.pr;
5679
}
5780

58-
return (
81+
const pr =
5982
envs?.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER ??
6083
envs?.SYSTEM_PULLREQUEST_PULLREQUESTID ??
61-
null
62-
);
84+
null;
85+
debug(`Using PR: ${pr}`, { enabled: output.debug });
86+
return pr;
6387
}
6488

6589
function _getService(): ProviderServiceParams["service"] {
@@ -84,7 +108,7 @@ function _getSHA(
84108

85109
let commit = envs?.BUILD_SOURCEVERSION ?? null;
86110

87-
if (_getPR(inputs)) {
111+
if (_getPR(inputs, output)) {
88112
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
89113
const mergeCommitMessage = childProcess
90114
.execFileSync("git", ["show", "--no-patch", "--format=%P"])
@@ -105,20 +129,24 @@ function _getSHA(
105129
}
106130
}
107131

108-
debug(`Using commit: ${commit}`, {
109-
enabled: output.debug,
110-
});
111-
132+
debug(`Using commit: ${commit}`, { enabled: output.debug });
112133
return commit;
113134
}
114135

115-
function _getSlug(inputs: ProviderUtilInputs): ProviderServiceParams["slug"] {
136+
function _getSlug(
137+
inputs: ProviderUtilInputs,
138+
output: Output,
139+
): ProviderServiceParams["slug"] {
116140
const { args, envs } = inputs;
117141
if (args?.slug && args.slug !== "") {
142+
debug(`Using slug: ${args.slug}`, { enabled: output.debug });
118143
return args.slug;
119144
}
120145

121-
return envs?.BUILD_REPOSITORY_NAME ?? parseSlugFromRemoteAddr("") ?? null;
146+
const slug =
147+
envs?.BUILD_REPOSITORY_NAME ?? parseSlugFromRemoteAddr("") ?? null;
148+
debug(`Using slug: ${slug}`, { enabled: output.debug });
149+
return slug;
122150
}
123151

124152
// eslint-disable-next-line @typescript-eslint/require-await
@@ -127,14 +155,14 @@ export async function getServiceParams(
127155
output: Output,
128156
): Promise<ProviderServiceParams> {
129157
return {
130-
branch: _getBranch(inputs),
131-
build: _getBuild(inputs),
132-
buildURL: _getBuildURL(inputs),
158+
branch: _getBranch(inputs, output),
159+
build: _getBuild(inputs, output),
160+
buildURL: _getBuildURL(inputs, output),
133161
commit: _getSHA(inputs, output),
134-
job: _getJob(inputs.envs),
135-
pr: _getPR(inputs),
162+
job: _getJob(inputs.envs, output),
163+
pr: _getPR(inputs, output),
136164
service: _getService(),
137-
slug: _getSlug(inputs),
165+
slug: _getSlug(inputs, output),
138166
};
139167
}
140168

0 commit comments

Comments
 (0)