Get the logs for the build container or a service container for a given step of a pipeline.

Retrieve the log file for a build container or service container. This endpoint supports (and encourages!) the use of [HTTP Range requests](https://tools.ietf.org/html/rfc7233) to deal with potentially very large log files.

Script bitbucket Verified

by hugo697 ยท 10/24/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 375 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Get the logs for the build container or a service container for a given step of a pipeline.
7
 * Retrieve the log file for a build container or service container.
8

9
This endpoint supports (and encourages!) the use of [HTTP Range requests](https://tools.ietf.org/html/rfc7233) to deal with potentially very large log files.
10
 */
11
export async function main(
12
  auth: Bitbucket,
13
  workspace: string,
14
  repo_slug: string,
15
  pipeline_uuid: string,
16
  step_uuid: string,
17
  log_uuid: string
18
) {
19
  const url = new URL(
20
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pipelines/${pipeline_uuid}/steps/${step_uuid}/logs/${log_uuid}`
21
  );
22

23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.text();
35
}
36