I have a project and I am converting this project into an exe file. These exe files are also saved in artifacts. I want to keep these artifacts files in the release section to perform version control.
I can’t always create artifacts in my last job. Artifacts are created in the job called build. So in short, Even though all operations are completed successfully, when I click on my-app.exe in the release section, I get a 404 page not found error with this url.
I want to be able to download my exe file in Artifacts in this release section. I can do this by connecting directly to the artifacts section, or I can explore the zip file in artifacts and put this file directly here. It doesnt matter. All I want is to access this exe file from the release section.
Since I created the exe file in the previous job, the artifacts are kept under that job. In order to access the artifact of the previous job before the next job, I keep the job id in a file while I was in the previous job and then pull the id from there.
This is my solution;
default:
image: docker:24.0.7
services:
- docker:24.0.7-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
stages:
- prepare_release
- release
prepare_release:
stage: prepare_release
before_script:
- echo "Setting up packages for Build"
- apk --no-cache add zip
script:
- docker buildx build -t my-docker-image --platform linux/arm64 . --build-arg TAG=$TAG
- container_id=$(docker run -d -t my-docker-image)
- mkdir -p artifacts/dist
- docker cp $container_id:/app/dist ./artifacts/dist
- echo "Zip distribution folder for Artifacts"
- zip -r artifacts.zip ./artifacts/dist
- echo "JOB_ID=$CI_JOB_ID" > artifacts/job.env # Create job.env in the artifacts directory
after_script:
- cat artifacts/job.env # Debug: Check the content of job.env
artifacts:
paths:
- artifacts/
expire_in: never
reports:
dotenv: artifacts/job.env # Specify the path to the job.env file
create_release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: prepare_release
artifacts: true
variables:
TAG: '$CI_COMMIT_TAG'
script:
- echo "Running the release job."
- JOB_ID=$(cat artifacts/job.env) # Read JOB_ID from job.env
- echo JOB_ID
rules:
- if: '$CI_COMMIT_TAG'
release:
name: 'Version $TAG'
tag_name: '$TAG'
description: "Release created using the release-cli. Release '$TAG'" # Use double quotes for variable interpolation
assets:
links:
- name: 'my-app.exe'
url: '$CI_SERVER_URL/$CI_PROJECT_PATH/-/jobs/$JOB_ID/artifacts/download'
I also upload artifacts (wheels) to the package registry (using twine), but I have to manually link them back in the release. Is your method manual as well or is there a way to get the link url and provide it to the release-cli job?
I don’t have a special way to get the URL of the wheel package. I normally craft it using API, predefined variables and version. Then pass the URL into the release-cli. There is unfortunately no “more” automated way to do this (AFAIK).
What is the simplest example, with one job - without artifacts/job.env? Please show. My CI needs just zip a few files from the repo and create a static link for third-party download. I tried this but got 404
image: registry.gitlab.com/gitlab-org/release-cli:latest
create_release:
variables:
TAG: '$CI_COMMIT_TAG'
script:
- apk add zip
- zip night.nzs id.txt form.ui script.js
rules:
- if: '$CI_COMMIT_TAG'
release:
tag_name: '$TAG'
name: 'Release $TAG'
description: Release created using the release-cli'
assets:
links:
- name: 'night.nzs'
url: '$CI_SERVER_URL/$CI_PROJECT_PATH/-/jobs/$JOB_ID/artifacts/download'
You’re missing the upload of the package. Release-CLI only creates a release, with a link. You are currently adding a link to the artifact - this could work by adding artifact section to your job, but I would not recommend this, since artifacts expire by default (I believe in 30 days or so).