How to view a raw build artifact without trigerring a download?

Viewed 473

On GitLab, you can browse and download job artifacts at annoyingly redirected URLs like these:

I can use these URLs as a download link in the release page. However, I'm distributing a userscript; users do not want to download them, they want to view them (so TamperMonkey and Greasemonkey can install them).

How do I make it so users can install a userscript from an arbitrary branch/tag/commit without quitting GitLab?

1 Answers

Unfortunately this is not supported for gitlab.com since workhorse always sets the content disposition as 'attachment' for artifacts, causing the browser to download the file. The only cases where the content disposition header is set as 'inline' is when viewing blobs.

Your best possible workaround would be to commit your built files to the repository (or another repository/snippets) and use the raw view. Conveniently, project snippets are basically a repository within a repository you can use for this purpose.

For example, you can use the project snippets API in your pipeline to create a snippet containing your user scripts, then use the snippet raw URL in your release. I tested this as working with tampermonkey.

Another possible workaround may be to host your files on GitLab pages, but each publish to GitLab pages will overwrite the previous publish, so you'll have to download all your previous artifacts and re-publish them every time if you want to support all your branches/tags.
This may also prove problematic, as concurrent pipelines (like a tag+branch pipeline) may have race-conditions unless you guard them with resource groups.

Related