logo
0
0
Login
Forkfromcnb/plugins/cnbcool/attachments, behind:main8 commits

Attachments Plugin

Supports uploading or downloading 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: 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.

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.

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

$: 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"

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/downloading release attachments
  • 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_REPO_SLUG Repository path, e.g., groupname/reponame

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_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

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_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

About

release附件插件

Language
TypeScript46.6%
Markdown45.3%
Shell4.5%
License1.7%
Others1.9%