actions / upload-artifact

MIT License
3.26k stars 739 forks source link

Getting artifact URL in steps after upload-artifact #382

Closed etaormm closed 11 months ago

etaormm commented 1 year ago

What would you like to be added?

Hi,

This suggestion has been discussed here in the GitHub community forum.

In a Github Actions job, after an upload-artifact step, I would like to get the URL of the published artifact in a subsequent step.

The idea is a job using the following steps:

Build a binary.
Upload the binary as artifact.
Trigger a REST API in some Web server, passing the URL of the artifact in a POST parameter, so that the remote server can download the artifact.

How would you get the URL of the artifact in a subsequent step?

I know that there is an Actions API currently in development. But, here, the question is about passing information from the upload-artifact step to the next step.

It could be something like this:

- name: Upload build
  uses: actions/upload-artifact@master
  with:
    name: installer
    path: installer.exe
    env-url: FOOBAR

- name: Use URL for something
  run: echo "${{ env.FOOBAR }}"

The last command would display something like:

https://github.com/user/repo/suites/123456/artifacts/789123

Why is this needed?

Last issue is open for two years, without any assignee or resolution -> https://github.com/actions/upload-artifact/issues/50

Can we assign someone to this?

gilzow commented 1 year ago

+1 to this enhancement

saerosV commented 1 year ago

+1, such an essential feature should not be ignored.

djthornton1212 commented 1 year ago

+1, to this request.

charleyoliveira commented 1 year ago

+1, to this request.

shalva97 commented 1 year ago

+1, to this request. Need it for sending a message to Slack and adding the link of artifact

Mickey9223 commented 1 year ago

1+, à cette amélioration

etaormm commented 1 year ago

@konradpabjan can we please assign someone to this?

semack commented 1 year ago

+1

sagarrajput commented 1 year ago

+1

agaertner commented 1 year ago

+1. It's been 5 years. Oh no...

davidpesce commented 1 year ago

I just discovered this need and am amazed it's been five years with zero implementation. I assumed I was doing something wrong in my yml file.

akshay-lyra commented 1 year ago

+1 This is a crucial feature that's limiting our automation.

For those who want to at least point users to the right area in the UI, you can use this url within your workflow: ${REPO_URL}/actions/runs/${{ github.run_id }}/#:~:text={YOUR_ARTIFACT_DISPLAY_NAME}

However, that might not work if the url is opened in the same tab.

bpetit commented 1 year ago

If useful, this line of bash gets the url to download the artifact of the workflow identified by ${GITHUB_RUN_ID} (if there is only one) :

url=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts | jq ".artifacts[] | select(.workflow_run.id==${GITHUB_RUN_ID}).url" | tr -d '"')/zip; curl -s -I -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "X-GitHub-Api-Version: 2022-11-28" $url | grep location | cut -d " " -f 2

However, I realized this doesn't work if launched in the same workflow that uploaded the artifact. It does work if launched in another workflow.

Maybe there is a link between this limitation (artifacts seem available only once the workflow is finished) and the fact that this feature has not been implemented so far in the upload-artifact action ?

sujanp-kr commented 1 year ago

+1 Also in this parallel universe. When happening 🤔

konradpabjan commented 11 months ago

Closing this as a duplicate of https://github.com/actions/upload-artifact/issues/50

The good news is that v4 was released today and with it an artifact ID is immediately available, so it is possible to construct a download URL with an extra API call. Not having the artifact ID until the end of a workflow run was the biggest limitation and that is gone: https://github.blog/changelog/2023-12-14-github-actions-artifacts-v4-is-now-generally-available/

We would like to change the format of the URL so it's even easier and more intuitive and once we have that outputting/returning a URL should be trivial. More information here https://github.com/actions/upload-artifact/issues/50#issuecomment-1856471599