GITLAB - Permalink for download latest Release form my repository
Asked Answered
C

3

5

Do you know if GitLab have any permalink for download LATEST Release (zip format) from my repositories?

Gitlab's documentations and issues is confused about this simple functionality..

Chantellechanter answered 8/8, 2019 at 17:6 Comment(0)
D
4

Unfortunately, there is not a static permalink that automatically redirects to the latest release without knowing the tag name beforehand, unless you script this functionality externally.

┌──────────────────────────────────────────────────┐
│ GitLab Repository                                │
├──────────────────────────────────────────────────┤
│ ┌──────────┐  ┌────────────────┐  ┌─────────────┐│
│ │Project ID│  │ Latest Release │  │ ZIP Download││
│ │  (12345) │  ├────────────────┤  │  Permalink  ││
│ │          │  │ Tag Name: v1.2 │  │             ││
│ └──────────┘  │ Asset URL      ├─►│(Dynamic URL)││
│               └────────────────┘  └─────────────┘│
└──────────────────────────────────────────────────┘

In this setup, you would need to dynamically generate the URL based on the latest release's tag name fetched via the API. That makes sure you always download the most current release in the desired format.

Install glab CLI, and make sure glab is authenticated to interact with your GitLab account (glab auth login).

Write a download_latest_release.sh script which fetches the latest release of a specified repository (gh release list) and downloads the assets (using glab project view).

#!/bin/bash

# Replace 'namespace/project' with your actual GitLab project path
PROJECT_PATH="namespace/project"

# Fetch the latest release data using glab
LATEST_RELEASE=$(glab release list --repo $PROJECT_PATH)

# Extract the tag name of the latest release
LATEST_TAG=$(echo "$LATEST_RELEASE" | grep -oP 'Tag:\s+\K\S+')

# Download the zip file of the latest release using the extracted tag
# Replace 'zip' with your desired file format
curl -LJO "https://gitlab.com/api/v4/projects/$(glab project view $PROJECT_PATH --jq '.id')/releases/$LATEST_TAG/downloads/zip"

echo "Downloaded the latest release: $LATEST_TAG"

The GitLab 14.9 documentation shown below introduced the concept of a permanent link to the latest release, but does not provide a static URL that directly downloads the latest release's assets without knowing the release tag. That script would fill this gap by dynamically determining the latest release tag and then constructing the URL for downloading the assets.


GitLab 14.9 (March 2022) could help, and proposes:

Permanent link to the latest version of a release

Prior to this update, to refer to the latest release of a project, users needed to know the exact version number.

We have now added a link to the latest release for a project.
This makes it much easier and more efficient to navigate to the latest release.

See Documentation and Issue.

You now have:

Latest release page is accessible through a permanent URL.
GitLab will redirect to the latest release page URL when it is visited.

The format of the URL is:

https://host/namespace/project/-/releases/permalink/latest

We also support, suffix path carry forward on the redirect to the latest release.
Example if release v14.8.0-ee is the latest release and has a readable link https://host/namespace/project/-/releases/v14.8.0-ee#release, then it can be addressed as:

 https://host/namespace/project/-/releases/permalink/latest#release.

And:

Permanent links to latest release assets:

The filepath from permanent links to release assets can be used in combination with permanent link to the latest release.
It is useful when we want to link a permanant URL to download an asset from the latest release.

The format of the URL is:

https://host/namespace/project/-/releases/permalink/latest/downloads/:filepath

If you have an asset with filepath for the v11.9.0-rc2 latest release in the gitlab-org namespace and gitlab-runner project on gitlab.com, for example:

{
 "name": "linux amd64",
 "filepath": "/binaries/gitlab-runner-linux-amd64",
 "url": "https://gitlab-runner-downloads.s3.amazonaws.com/v11.9.0-rc2/binaries/gitlab-runner-linux-amd64",
 "link_type": "other"
}

This asset has a direct link of:

https://gitlab.com/gitlab-org/gitlab-runner/-/releases/permalink/latest/downloads/binaries/gitlab-runner-linux-amd64
Diploma answered 22/3, 2022 at 18:23 Comment(2)
pasting the same confusing docs the questioner asks about, is not exactly a great way to answer this question :)Levey
@Levey Thank you for your feedback, good point. I have edited the answer to include first a practical solution to the OP's question.Diploma
P
2

There is not currently an API endpoint to get the latest release. There is a feature proposal at https://gitlab.com/gitlab-org/gitlab-ce/issues/26254.

Prisage answered 8/8, 2019 at 17:13 Comment(0)
L
1

As of 2024-04 Gitlab does not provide permanent links to the source code archives that are automatically created for releases ("source code assets"). This issue is tracked here. The next best thing to provide to humans is linking to the release itself:

https://host/namespace/project/-/releases/permalink/latest
Levey answered 23/4 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.