Supports uploading or downloading attachments for commits and releases. Currently supports uploading files up to 64GB.
cnbcool/attachments:latest
The following events support upload and download attachment operations:
type: Operation type, default value is UPLOAD, optional.
UPLOAD: Upload attachmentsDOWNLOAD: Download attachmentstag: Tag name, required when operating on a specific tag, optional.
The tag must have a corresponding release to upload attachments.commit: Commit SHA, long hash, optional.attachments: File name, required.slug: Repository path, optional. Defaults to the repository that triggered the current pipeline.
Not required for uploads within the same repository.
Use this parameter to specify the repository path for cross-repository uploads.endpoint: URL for uploading or downloading attachments, optional.
Defaults to the current platform's OPENAPI address. Not required for operations within the same platform.
If you need to upload attachments across platforms, such as from CNB PAAS version to CNB SAAS version,
you can use this parameter to specify the endpoint, e.g., https://api.cnb.cool.token: Token for uploading or downloading attachments, optional.
Defaults to the current user's temporary credentials.
Required for cross-platform uploads or cross-repository uploads
when the current user doesn't have repository permissions.When type is UPLOAD, you must provide the relative path of the files to upload;
For multiple files, separate with commas or use an array. Supports glob expression matching.
When type is DOWNLOAD, provide the file name of the file to download.
When providing a path,
the code will automatically get the file name and download to the working directory by default.
When neither tag nor commit is provided, the default target is:
For tag_push and tag_deploy.* events, tag takes the environment variable $CNB_BRANCH,
and operates on the attachments of the release corresponding to the tag.
For other events, commit takes the environment variable $CNB_COMMIT,
and operates on the attachments of the commit.
When both tag and commit are provided,
the default target is the release corresponding to the tag (uploads are not possible without a release).
{
"FILES": "file1.txt,file2.txt,file3.txt"
}
For uploads, the FILES parameter (relative path of uploaded files, separated by commas) is output to the environment variable,
which can be exported to the environment variable through exports.
$:
tag_push:
- stages:
- name: Upload attachments to release
image: cnbcool/attachments:latest
settings:
attachments:
- "./*.txt"
exports:
FILES: FILES
- name: Output files
script: echo $FILES
$:
tag_push:
- stages:
- name: Upload attachments to release
image: cnbcool/attachments:latest
settings:
attachments:
- "./*.txt"
- name: Support for negation patterns, the example below will exclude ./test1.txt file
image: cnbcool/attachments:latest
settings:
attachments:
- "./*.txt"
- "!./test1.txt"
- name: Download release attachments
image: cnbcool/attachments:latest
settings:
type: DOWNLOAD
attachments: "./test1.txt,./test2.txt"
main:
push:
- stages:
- name: Upload commit attachments, multiple files in array format
image: cnbcool/attachments:latest
settings:
attachments:
- "./test1.txt"
- "./test2.txt"
- name: Upload commit attachments, multiple files comma-separated
image: cnbcool/attachments:latest
settings:
attachments: "./test1.txt,./test2.txt"
- name: Download commit attachments
image: cnbcool/attachments:latest
settings:
type: DOWNLOAD
attachments: "test1.txt,test2.txt"
Example use case: When build artifacts from a private repository need to be uploaded to a public repository (if you want to make build artifacts public but keep the repository private, you can create a public repository specifically for publishing build artifacts). The following configuration can achieve cross-repository attachment uploads:
$:
tag_push:
- stages:
- name: Cross-repository upload of release attachments
image: cnbcool/attachments:latest
settings:
attachments:
- "./*.txt"
# Upload attachments to specified repository
slug: groupname/reponame
- name: Cross-repository download of release attachments
image: cnbcool/attachments:latest
settings:
type: DOWNLOAD
attachments: "./test1.txt,./test2.txt"
# Download attachments from specified repository
slug: groupname/reponame
Only supports uploads between different CNB platforms, for example, from CNB PAAS version to CNB SAAS version.
$:
tag_push:
- stages:
- name: Cross-platform cross-repository upload of release attachments
image: cnbcool/attachments:latest
settings:
attachments:
- "./*.txt"
# Upload attachments to specified repository across platforms
slug: groupname/reponame
endpoint: https://api.cnb.cool
# Token is required for cross-platform operations
token: xxxxx
- name: Cross-platform cross-repository download of release attachments
image: cnbcool/attachments:latest
settings:
type: DOWNLOAD
attachments: "./test1.txt,./test2.txt"
# Download attachments from specified repository across platforms
slug: groupname/reponame
endpoint: https://api.cnb.cool
# Token is required for cross-platform operations
token: xxxxx
Parameter description:
PLUGIN_ATTACHMENTS Attachment list, multiple files separated by commasPLUGIN_TYPE Upload/Download, UPLOAD or DOWNLOAD, default is UPLOADPLUGIN_COMMIT Commit ID, required for uploading/downloading commit attachmentsPLUGIN_TAG Tag name, required for uploading/downloading release attachmentsCNB_TOKEN CNB API Token, create and obtain from Personal Settings -> Access Tokens,
make sure to select repo-contents read/write permissionsCNB_API_ENDPOINT CNB API Endpoint, for CNB SAAS version it's https://api.cnb.coolCNB_REPO_SLUG Repository path, e.g., groupname/reponame# Upload commit attachments
docker run --rm \
-e TZ=Asia/Shanghai \
-e CNB_TOKEN='xxxx' \
-e CNB_API_ENDPOINT='https://api.cnb.cool' \
-e CNB_REPO_SLUG='groupname/reponame' \
-e PLUGIN_COMMIT='xxx' \
-e PLUGIN_ATTACHMENTS='./xxx.png' \
-v $(pwd):$(pwd) \
-w $(pwd) \
cnbcool/attachments:latest
# Download commit attachments
docker run --rm \
-e TZ=Asia/Shanghai \
-e CNB_TOKEN='xxxx' \
-e CNB_API_ENDPOINT='https://api.cnb.cool' \
-e CNB_REPO_SLUG='groupname/reponame' \
-e PLUGIN_COMMIT='xxx' \
-e PLUGIN_ATTACHMENTS='xxx.png' \
-e PLUGIN_TYPE='DOWNLOAD' \
-v $(pwd):$(pwd) \
-w $(pwd) \
cnbcool/attachments:latest
Requires that the tag already exists and a release has been created
# Upload release attachments
docker run --rm \
-e TZ=Asia/Shanghai \
-e CNB_TOKEN='xxxx' \
-e CNB_API_ENDPOINT='https://api.cnb.cool' \
-e CNB_REPO_SLUG='groupname/reponame' \
-e PLUGIN_TAG='v1.0.0' \
-e PLUGIN_ATTACHMENTS='./xxx.png' \
-v $(pwd):$(pwd) \
-w $(pwd) \
cnbcool/attachments:latest
# Download release attachments
docker run --rm \
-e TZ=Asia/Shanghai \
-e CNB_TOKEN='xxxx' \
-e CNB_API_ENDPOINT='https://api.cnb.cool' \
-e CNB_REPO_SLUG='groupname/reponame' \
-e PLUGIN_TAG='v1.0.0' \
-e PLUGIN_ATTACHMENTS='xxx.png' \
-e PLUGIN_TYPE='DOWNLOAD' \
-v $(pwd):$(pwd) \
-w $(pwd) \
cnbcool/attachments:latest