admin管理员组

文章数量:1355600

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

本文标签: Download artifacts from a different GitHub repo with gh cliStack Overflow