Implement fallback to release-cli when glab is not available
What does this MR do and why?
Implement fallback to release-cli when glab is not available
This change updates the release job script generation to first attempt
using glab for creating releases, with a graceful fallback to
release-cli if glab is not available or its version is too old.
This ensures backward compatibility while preparing for the
release-cli deprecation in GitLab 18.0.
Changes include:
- Add Windows PowerShell support for
glabcommands - Display warning message when falling back to
release-cli - Improve error handling for both Unix and Windows environments
- Preserve catalog publish functionality across both tools
These changes is behind the feature flag ci_glab_for_release
(#524346 (closed))
Related to cli#7450 (closed)
flowchart TD
A[Releaser for a Catalog release] -->|creating commands| B{{FF ci_glab_for_release}}
B -->|true| C{{glab version OK?}}
B -->|false| D{{FF ci_release_cli_catalog_publish_option}}
C -->|true| E{{FF ci_release_cli_catalog_publish_option}}
C -->|false| F{{FF ci_release_cli_catalog_publish_option}}
E -->|true| G[
• 'glab release create --publish-to-catalog'
• no 'legacy_catalog_publish' is sent from the Runner
• 'publish_catalog?' will be false for 'Releases::CreateService'
• API 'catalog/publish' will be called via glab to publish
]
E -->|false| H[
• 'glab release create'
• no 'legacy_catalog_publish' is sent from the Runner
• 'publish_catalog?' will be true for 'Releases::CreateService'
]
F -->|true| I[
• 'release-cli create --catalog-publish'
• 'legacy_catalog_publish' is sent from the Runner
• 'publish_catalog?' will be true for 'Releases::CreateService'
]
F -->|false| J[
• 'release-cli create'
• no 'legacy_catalog_publish' is sent from the Runner
• 'publish_catalog?' will be true for 'Releases::CreateService'
]
D -->|true| I
D -->|false| J
Screenshots or screen recordings
Linux and Windows
.unix_command: &unix_command
- |
if command -v glab &> /dev/null; then
if [ "$(printf "%s\n%s" "1.53.0" "$(glab --version | grep -oE '[0-9]+.[0-9]+.[0-9]+')" | sort -V | head -n1)" = "1.53.0" ]; then
export GITLAB_HOST=$CI_SERVER_URL
glab auth login --job-token $CI_JOB_TOKEN --hostname $CI_SERVER_FQDN --api-protocol $CI_SERVER_PROTOCOL
glab -R $CI_PROJECT_PATH release create "v11.11.12" --name "Release 11.11.12" --experimental-notes-text-or-file "Created using the release-cli" --ref "glab_release_cli_migration" --tag-message "Annotated tag message" --no-update --no-close-milestone
else
echo "Warning: release-cli will not be supported after 18.0. Please use glab version >= 1.53.0. Troubleshooting: http://localhost/help/user/project/releases/_index.md#gitlab-cli-version-requirement"
release-cli create --name "Release 11.11.13" --description "Created using the release-cli" --tag-name "v11.11.13" --tag-message "Annotated tag message" --ref "glab_release_cli_migration"
fi
else
echo "Warning: release-cli will not be supported after 18.0. Please use glab version >= 1.53.0. Troubleshooting: http://localhost/help/user/project/releases/_index.md#gitlab-cli-version-requirement"
release-cli create --name "Release 11.11.14" --description "Created using the release-cli" --tag-name "v11.11.14" --tag-message "Annotated tag message" --ref "glab_release_cli_migration"
fi
.windows_command: &windows_command
- |
if (Get-Command glab -ErrorAction SilentlyContinue) {
$glabVersion = (glab --version | Select-String -Pattern '\d+\.\d+\.\d+').Matches[0].Value
if ([version]"1.53.0" -le [version]$glabVersion) {
$env:GITLAB_HOST = $env:CI_SERVER_URL
glab auth login --job-token $env:CI_JOB_TOKEN --hostname $env:CI_SERVER_FQDN --api-protocol $env:CI_SERVER_PROTOCOL
glab -R $env:CI_PROJECT_PATH release create "v11.11.15" --name "Release 11.11.15" --experimental-notes-text-or-file "Created using the release-cli" --ref "glab_release_cli_migration" --tag-message "Annotated tag message" --no-update --no-close-milestone
}
else {
Write-Output "Warning: release-cli will not be supported after 18.0. Please use glab version >= 1.53.0. Troubleshooting: http://localhost/help/user/project/releases/_index.md#gitlab-cli-version-requirement"
release-cli create --name "Release 11.11.16" --description "Created using the release-cli" --tag-name "v11.11.16" --tag-message "Annotated tag message" --ref "glab_release_cli_migration"
}
}
else {
Write-Output "Warning: release-cli will not be supported after 18.0. Please use glab version >= 1.53.0. Troubleshooting: http://localhost/help/user/project/releases/_index.md#gitlab-cli-version-requirement"
release-cli create --name "Release 11.11.17" --description "Created using the release-cli" --tag-name "v11.11.17" --tag-message "Annotated tag message" --ref "glab_release_cli_migration"
}
unix-release-cli-0-22-0:
image: registry.gitlab.com/gitlab-org/release-cli:v0.22.0
script:
- *unix_command
unix-release-cli-0-20-0:
image: registry.gitlab.com/gitlab-org/release-cli:v0.20.0
script:
- *unix_command
unix-release-cli-0-18-0:
image: registry.gitlab.com/gitlab-org/release-cli:v0.18.0
script:
- *unix_command
windows-glab-1-53-0:
tags: [saas-windows-medium-amd64]
script:
- wget "https://gitlab.com/gitlab-org/release-cli/-/releases/v0.22.0/downloads/bin/release-cli-windows-amd64.exe" -OutFile "release-cli.exe"
- Set-Alias -Name release-cli -Value "./release-cli.exe"
- wget "https://gitlab.com/gitlab-org/cli/-/releases/v1.53.0/downloads/glab.exe" -OutFile "glab.exe"
- Set-Alias -Name glab -Value "./glab.exe"
- *windows_command
windows-glab-1-52-0:
tags: [saas-windows-medium-amd64]
script:
- wget "https://gitlab.com/gitlab-org/release-cli/-/releases/v0.22.0/downloads/bin/release-cli-windows-amd64.exe" -OutFile "release-cli.exe"
- Set-Alias -Name release-cli -Value "./release-cli.exe"
- wget "https://gitlab.com/gitlab-org/cli/-/releases/v1.52.0/downloads/glab.exe" -OutFile "glab.exe"
- Set-Alias -Name glab -Value "./glab.exe"
- *windows_command
windows-glab-release-cli:
tags: [saas-windows-medium-amd64]
script:
- wget "https://gitlab.com/gitlab-org/release-cli/-/releases/v0.22.0/downloads/bin/release-cli-windows-amd64.exe" -OutFile "release-cli.exe"
- Set-Alias -Name release-cli -Value "./release-cli.exe"
- *windows_command
Example; https://gitlab.com/furkanayhan/test-project/-/pipelines/1724563793
Macos
.unix_command: &unix_command
- |
if command -v glab &> /dev/null; then
if [ "$(printf "%s\n%s" "1.53.0" "$(glab --version | grep -oE '[0-9]+.[0-9]+.[0-9]+')" | sort -V | head -n1)" = "1.53.0" ]; then
export GITLAB_HOST=$CI_SERVER_URL
glab auth login --job-token $CI_JOB_TOKEN --hostname $CI_SERVER_FQDN --api-protocol $CI_SERVER_PROTOCOL
glab -R $CI_PROJECT_PATH release create "v11.12.12" --name "Release 11.12.12" --experimental-notes-text-or-file "Created using the release-cli" --ref "glab_release_cli_migration" --tag-message "Annotated tag message" --no-update --no-close-milestone
else
echo "Warning: release-cli will not be supported after 18.0. Please use glab version >= 1.53.0. Troubleshooting: http://localhost/help/user/project/releases/_index.md#gitlab-cli-version-requirement"
release-cli create --name "Release 11.12.13" --description "Created using the release-cli" --tag-name "v11.12.13" --tag-message "Annotated tag message" --ref "glab_release_cli_migration"
fi
else
echo "Warning: release-cli will not be supported after 18.0. Please use glab version >= 1.53.0. Troubleshooting: http://localhost/help/user/project/releases/_index.md#gitlab-cli-version-requirement"
release-cli create --name "Release 11.12.14" --description "Created using the release-cli" --tag-name "v11.12.14" --tag-message "Annotated tag message" --ref "glab_release_cli_migration"
fi
default:
tags: [saas-macos-medium-m1]
macos-glab-1-53-0:
script:
- curl -L "https://gitlab.com/gitlab-org/release-cli/-/releases/v0.22.0/downloads/bin/release-cli-darwin-arm64" -o release-cli
- chmod +x ./release-cli
- export PATH="$PWD:$PATH"
- curl -L "https://gitlab.com/gitlab-org/cli/-/releases/v1.53.0/downloads/glab_1.53.0_darwin_arm64.tar.gz" -o glab.tar.gz
- tar -xzf glab.tar.gz
- chmod +x ./bin/glab
- export PATH="$PWD/bin:$PATH"
- glab --version
- release-cli --version
- *unix_command
macos-glab-1-52-0:
script:
- curl -L "https://gitlab.com/gitlab-org/release-cli/-/releases/v0.22.0/downloads/bin/release-cli-darwin-arm64" -o release-cli
- chmod +x ./release-cli
- export PATH="$PWD:$PATH"
- curl -L "https://gitlab.com/gitlab-org/cli/-/releases/v1.52.0/downloads/glab_1.52.0_darwin_arm64.tar.gz" -o glab.tar.gz
- tar -xzf glab.tar.gz
- chmod +x ./bin/glab
- export PATH="$PWD/bin:$PATH"
- glab --version
- release-cli --version
- *unix_command
macos-release-cli:
script:
- curl -L "https://gitlab.com/gitlab-org/release-cli/-/releases/v0.22.0/downloads/bin/release-cli-darwin-arm64" -o release-cli
- chmod +x ./release-cli
- export PATH="$PWD:$PATH"
- release-cli --version
- *unix_command
Example; https://gitlab.com/furkanayhan/test-project/-/pipelines/1726158463
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.