Skip to content

Instantly share code, notes, and snippets.

@alebaffa
Forked from umohi/download-github-artifact
Created December 17, 2022 07:27
Show Gist options
  • Save alebaffa/b94780ad3ae6fa484fe69d4607c3d506 to your computer and use it in GitHub Desktop.
Save alebaffa/b94780ad3ae6fa484fe69d4607c3d506 to your computer and use it in GitHub Desktop.
use curl to download release artifact from github private repository
# in order to download release artifacts from github, you have to first retreive the
# list of asset URLs using the github repo REST API. Use the asset URL to download
# the artifact as a octet-stream data stream. You will need to get an access token
# from "settings -> developer settings -> personal access tokens" on the github UI
#!/bin/bash -e
owner="MY_ORG_NAME"
repo="MY_REPO_NAME"
tag="ARTIFACT_TAG"
artifact="ARTIFACT_NAME"
token="MY_ACCESS_TOKEN"
list_asset_url="https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}?access_token=${token}"
# get url for artifact with name==$artifact
asset_url=$(curl "${list_asset_url}" | jq ".assets[] | select(.name==\"${artifact}\") | .url" | sed 's/\"//g')
# download the artifact
curl -vLJO -H 'Accept: application/octet-stream' \
"${asset_url}?access_token=${token}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment