Download artifacts from a different GitHub repo with gh cli - Stack Overflow

Looking at this documentation I can use curl version of the provided example:curl -L -H "Accept:

Looking at this documentation I can use curl version of the provided example:

curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer GITHUB_CODE" -H "X-GitHub-Api-Version: 2022-11-28"  --output c:\\temp\\artifact.zip

Notice: output argument. This code downloads the artifacts and saves it as a zip file. However I want to use GitHub CLI for this purpose (login has been successful):

gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/USER/REPO/actions/artifacts/ARTIFACT_ID/zip

As far as I understand, this code just prints the text representation of the binary file since I see a plain text in the output which is related to my artifacts. But how to save this output into the binary zip file? Just redirecting output gh .. > res.zip doesn't work (saves a corrupted file). I also don't see arguments in the gh binary that can help with this

Looking at this documentation I can use curl version of the provided example:

curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer GITHUB_CODE" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github/repos/USER/REPO/actions/artifacts/ARTIFACT_ID/zip --output c:\\temp\\artifact.zip

Notice: output argument. This code downloads the artifacts and saves it as a zip file. However I want to use GitHub CLI for this purpose (login has been successful):

gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/USER/REPO/actions/artifacts/ARTIFACT_ID/zip

As far as I understand, this code just prints the text representation of the binary file since I see a plain text in the output which is related to my artifacts. But how to save this output into the binary zip file? Just redirecting output gh .. > res.zip doesn't work (saves a corrupted file). I also don't see arguments in the gh binary that can help with this

Share Improve this question edited Mar 28 at 19:39 dododo asked Mar 28 at 18:21 dodododododo 4,8392 gold badges19 silver badges44 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1 +50

At the moment, it is not possible to redirect the output of the gh api call to download artifacts as a zip file. An alternative is to use the gh run download command to download the artifacts.

By default, this command downloads the latest artifact created and uploaded through GitHub Actions. You can specify the <run-id> to select an artifact from a specific workflow run. You can also filter the artifacts by name by specifying the -n or --name option.

# Download a specific artifact within a run
$ gh run download <run-id> -n <name>

You can also specify the -D or --dir option to specify the directory where the artifacts will be downloaded.

Reference: Docs.

Update: You can use the -R or --repo option to specify another repo from which you want to download the artifacts.

Options inherited from parent commands

-R, --repo <[HOST/]OWNER/REPO>

Select another repository using the [HOST/]OWNER/REPO format

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744019173a4544543.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信