logo
10
8
WeChat Login

Attachments Plugin

Supports uploading or downloading or deleting attachments for commits and releases. Currently supports uploading files up to 64GB.

Image

cnbcool/attachments:latest

Supported Events

The following events support upload and download attachment operations:

  • push
  • branch.create
  • branch.delete
  • pull_request
  • pull_request.target
  • pull_request.approved
  • pull_request.changes_requested
  • pull_request.mergeable
  • pull_request.merged
  • tag_push
  • vscode
  • auto_tag
  • tag_deploy.*

Input Parameters

  • type: Operation type, default value is UPLOAD, optional.
    • UPLOAD: Upload attachments
    • DOWNLOAD: Download attachments
  • tag: 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: Attachments. Upload operations support specifying file names and the attachments Time-To-Live ttl. Delete operations default to deleting all attachments, while for other operations, this field is 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.
  • ttl: The Time-To-Live for attachments, measured in days. This field is optional. Defaults to 0 days, meaning the attachments will exist permanently. It is optional when uploading attachments and should be omitted for other operations. This parameter sets the expiration time for all attachments, with a lower priority than the ttl set for individual attachments.

attachments

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. Supports setting the attachment Time-To-Live ttl in days, which is optional. Defaults to 0 days, indicating that the attachments will exist permanently. The format is {file: ttl}.

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.

tag/commit

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).

Output Parameters

{ "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

Usage in Cloud Native Build

Release Attachments

The following configuration takes the push event as an example: when uploading a release attachment, it is necessary to specify a tag for each file, as well as the duration for which the file will be available.

main: push: - stages: - name: Specify a tag to upload the release attachment. image: cnbcool/attachments:latest settings: tag: v1.0.0 attachments: - "./test1.txt"

The following configuration takes the push event as an example: when uploading a release attachment, it is necessary to specify a tag for each file, as well as the duration for which the file will be available.

main: push: - stages: - name: Specify a tag to upload release attachments, and specify the retention period for each file. image: cnbcool/attachments:latest settings: tag: v1.0.0 attachments: "./test1.txt": 1 "./test2.txt": 2 # Direct assignment of object values # attachments: {"./test1.txt": 1, "./test2.txt": 2}

The following configuration takes the push event as an example: when uploading a release attachment, it is necessary to specify a tag for each file, as well as the duration for which the file will be available.

main: push: - stages: - name: Specify a tag to upload release attachments, and specify the retention period for each file. image: cnbcool/attachments:latest settings: tag: v1.0.0 attachments: - "./test1.txt" - "./test2.txt" ttl: 1

The following configuration takes the tag_push event as an example. The value of tag is set to the environment variable $CNB_BRANCH, so it does not need to be specified explicitly.

$: tag_push: - stages: - name: Release upload the attachment. image: cnbcool/attachments:latest settings: attachments: - "./*.txt" - name: The negative mode is supported; the example below will exclude the ./test1.txt file. image: cnbcool/attachments:latest settings: attachments: - "./*.txt" - "!./test1.txt" - name: Release download the attachment. image: cnbcool/attachments:latest settings: type: DOWNLOAD attachments: "./test1.txt,./test2.txt" - name: Delete all attachments associated with this release. image: cnbcool/attachments:latest settings: type: DELETE - name: Delete the specified attachments associated with this release. image: cnbcool/attachments:latest settings: type: DELETE attachments: - "./test1.txt" - "./*.zip" # attachments: "./test1.txt,./*.zip"

Commit Attachments

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"

Cross-Repository Attachment Uploads

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

Cross-Platform Attachment Uploads

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

Using Docker Image to Directly Upload/Download Attachments

Parameter description:

  • PLUGIN_ATTACHMENTS Attachment list, multiple files separated by commas
  • PLUGIN_TYPE Upload/Download, UPLOAD or DOWNLOAD, default is UPLOAD
  • PLUGIN_COMMIT Commit ID, required for uploading/downloading commit attachments
  • PLUGIN_TAG Tag name, required for uploading release attachments.Optional for downloading release attachments (defaults to latest release). Download fails if no latest release exists and this parameter is omitted
  • CNB_TOKEN CNB API Token, create and obtain from Personal Settings -> Access Tokens, make sure to select repo-contents read/write permissions
  • CNB_API_ENDPOINT CNB API Endpoint, for CNB SAAS version it's https://api.cnb.cool
  • CNB_WEB_ENDPOINT CNB WEB Endpoint,for CNB SAAS version it's https://cnb.cool
  • CNB_REPO_SLUG Repository path, e.g., groupname/reponame
  • CNB_IS_TAG Whether it is a tag, trueor false, defaults to false. When set to true, it indicates uploading/downloading release attachments. When downloading the latest release attachment without specifying PLUGIN_TAG, this parameter must be set to true

Upload/Download Commit Attachments

# Upload commit attachments docker run --rm \ -e TZ=Asia/Shanghai \ -e CNB_TOKEN='xxxx' \ -e CNB_API_ENDPOINT='https://api.cnb.cool' \ -e CNB_WEB_ENDPOINT='https://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 # Upload commit attachments and specify ttl for each attachment. docker run --rm \ -e TZ=Asia/Shanghai \ -e CNB_TOKEN='xxxx' \ -e CNB_API_ENDPOINT='https://api.cnb.cool' \ -e CNB_WEB_ENDPOINT='https://cnb.cool' \ -e CNB_REPO_SLUG='groupname/reponame' \ -e PLUGIN_COMMIT='xxx' \ -e PLUGIN_ATTACHMENTS='{"./xxx.png":2, "./xxx.txt":1}' \ -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

Upload/Download Release Attachments

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_WEB_ENDPOINT='https://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 # Upload release attachments and specify ttl for each attachment. docker run --rm \ -e TZ=Asia/Shanghai \ -e CNB_TOKEN='xxxx' \ -e CNB_API_ENDPOINT='https://api.cnb.cool' \ -e CNB_WEB_ENDPOINT='https://cnb.cool' \ -e CNB_REPO_SLUG='groupname/reponame' \ -e PLUGIN_TAG='v1.0.0' \ -e PLUGIN_ATTACHMENTS='./xxx.png, ./xxx.txt' \ -e PLUGIN_TTL = 2 \ -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 # Download the latest release attachment without specifying PLUGIN_TAG docker run --rm \ -e TZ=Asia/Shanghai \ -e CNB_TOKEN='xxx' \ -e CNB_API_ENDPOINT='https://api.cnb.cool' \ -e CNB_REPO_SLUG='groupname/reponame' \ -e PLUGIN_ATTACHMENTS='xxx.png' \ -e PLUGIN_TYPE='DOWNLOAD' \ -e CNB_IS_TAG='true' \ -v $(pwd):$(pwd) \ -w $(pwd) \ attachments:test

About

release附件插件

38.79 MiB
10 forks8 stars6 branches4 TagREADMEMIT license
Language
TypeScript85.8%
JavaScript8.5%
Shell4.7%
Dockerfile1%