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'