|
| 1 | +--- |
| 2 | +# generated by https://github.com/hashicorp/terraform-plugin-docs |
| 3 | +page_title: "gitlab_artifact_file Data Source - terraform-provider-gitlab" |
| 4 | +subcategory: "" |
| 5 | +description: |- |
| 6 | + The gitlab_artifact_file data source allows downloading a single artifact file from a specific job in the latest successful pipeline for a given reference (branch, tag, or commit). |
| 7 | + Upstream API: GitLab REST API docs https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-from-specific-tag-or-branch |
| 8 | +--- |
| 9 | + |
| 10 | +# gitlab_artifact_file (Data Source) |
| 11 | + |
| 12 | +The `gitlab_artifact_file` data source allows downloading a single artifact file from a specific job in the latest successful pipeline for a given reference (branch, tag, or commit). |
| 13 | +**Upstream API**: [GitLab REST API docs](https://docs.gitlab.com/ee/api/job_artifacts.html#download-a-single-artifact-file-from-specific-tag-or-branch) |
| 14 | + |
| 15 | +## Example Usage |
| 16 | + |
| 17 | +```terraform |
| 18 | +# Download a text artifact file from the latest successful pipeline |
| 19 | +data "gitlab_artifact_file" "config" { |
| 20 | + project = "namespace/myproject" |
| 21 | + job = "build-job" |
| 22 | + ref = "main" |
| 23 | + artifact_path = "config/settings.json" |
| 24 | +} |
| 25 | +
|
| 26 | +# Use the artifact content |
| 27 | +output "config_content" { |
| 28 | + value = data.gitlab_artifact_file.config.content |
| 29 | +} |
| 30 | +
|
| 31 | +# Download a binary artifact file using base64 encoding |
| 32 | +data "gitlab_artifact_file" "binary" { |
| 33 | + project = "namespace/myproject" |
| 34 | + job = "build-job" |
| 35 | + ref = "v1.0.0" |
| 36 | + artifact_path = "dist/app.zip" |
| 37 | +} |
| 38 | +
|
| 39 | +output "binary_content_base64" { |
| 40 | + value = data.gitlab_artifact_file.binary.content_base64 |
| 41 | +} |
| 42 | +
|
| 43 | +# Download artifact from a specific tag |
| 44 | +data "gitlab_artifact_file" "release" { |
| 45 | + project = "12345" |
| 46 | + job = "release-job" |
| 47 | + ref = "v2.1.0" |
| 48 | + artifact_path = "release-notes.txt" |
| 49 | +} |
| 50 | +
|
| 51 | +# Download a larger artifact with custom size limit |
| 52 | +data "gitlab_artifact_file" "large_artifact" { |
| 53 | + project = "namespace/myproject" |
| 54 | + job = "build-job" |
| 55 | + ref = "main" |
| 56 | + artifact_path = "dist/large-file.zip" |
| 57 | + max_size_bytes = 20971520 # 20MB |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +<!-- schema generated by tfplugindocs --> |
| 62 | +## Schema |
| 63 | + |
| 64 | +### Required |
| 65 | + |
| 66 | +- `artifact_path` (String) Path to the artifact file within the job's artifacts archive. This path is relative to the archive contents (not the local filesystem). Ensure each `gitlab_artifact_file` data source in your configuration uses a unique artifact_path to avoid ambiguity. |
| 67 | +- `job` (String) The name of the job. |
| 68 | +- `project` (String) The ID or URL-encoded path of the project. |
| 69 | +- `ref` (String) The name of the branch, tag, or commit SHA. |
| 70 | + |
| 71 | +### Optional |
| 72 | + |
| 73 | +- `max_size_bytes` (Number) Maximum bytes to read from the artifact. Defaults to 10MB (10485760 bytes). |
| 74 | + |
| 75 | +### Read-Only |
| 76 | + |
| 77 | +- `content` (String) The content of the artifact file as a UTF-8 string. Use `content_base64` for binary files. |
| 78 | +- `content_base64` (String) The content of the artifact file as a base64-encoded string. Useful for binary files. |
| 79 | +- `id` (String) The ID of this datasource. In the format `<project>:<ref>:<job>:<artifact_path>`. |
0 commit comments