Reputation: 179
I am using a private gitlab-runner
to build an ISO and then upload the ISO and its log to my S3 bucket. This section of the pipeline works without a hitch, but I recently decided to create "release" upon a successful pipeline. For this reason, I am using the following .gitlab-ci.yml
:
stages:
- build
- release
build_amd64:
stage: build
# Do not run the pipeline if the following files/directories are modified:
# except:
# changes:
# - Pictures/
# - .gitignore
# - FUNDING.yml
# - LICENSE
# - README.md
tags:
- digitalocean
timeout: 4 hours
before_script:
# Make sure the dependencies for the build are up-to-date:
- /usr/bin/apt update
- /usr/bin/apt install --only-upgrade -y curl git live-build cdebootstrap
# Save Job ID
- echo 'Saving $CI_JOB_ID to .env'
- echo BUILD_JOB_ID=$CI_JOB_ID >> .env
script:
# Build the ISO:
- ./build.sh --arch amd64 --variant i3_gaps --verbose
after_script:
- |
if [ $CI_JOB_STATUS == 'success' ]; then
# Remove everything except the "images" folder:
shopt -s extglob
/usr/bin/rm -rf !(images/)
# Upload log:
# /usr/bin/s3cmd put ./images/log s3://$S3_BUCKET/download/log
# Set log access to public:
# /usr/bin/s3cmd setacl s3://$S3_BUCKET/download/log --acl-public
# Upload iso:
# /usr/bin/s3cmd put ./images/iso s3://$S3_BUCKET/download/iso
# Set iso access to public:
# /usr/bin/s3cmd setacl s3://$S3_BUCKET/download/iso --acl-public
else
# If pipeline fails, skip the upload process:
echo 'Skipping upload process due to job failure'
sleep 5; /usr/sbin/reboot
/usr/bin/screen -dm /bin/sh -c '/usr/bin/sleep 5; /usr/sbin/reboot;'
fi
artifacts:
reports:
# Ensure that we have access to .env in the next stage
dotenv: .env
publish_release:
image: registry.gitlab.com/gitlab-org/release-cli:latest
stage: release
needs:
- job: build_amd64
artifacts: true
release:
name: 'ISO | $CI_COMMIT_SHORT_SHA | $BUILD_JOB_ID'
description: "Created and released via Gitlab CI/CD."
tag_name: "$CI_COMMIT_SHORT_SHA"
ref: '$CI_COMMIT_SHA'
assets:
links:
- name: "ISO"
url: "https://foo.bar"
link_type: "image"
- name: "Build Log"
URL: "https://foo.bar"
link_type: "other"
However I have realized that when the release
job runs, it creates the release without any issues, but then creates a new pipeline with the new tag (in this case$CI_COMMIT_SHORT_SHA
), instead of initially creating this new pipeline with this tag, instead of main
branch.
I checked the documentation but I cannot find anything regarding this matter.
Is there a way to not run a pipeline when a release is published?
Upvotes: 0
Views: 329
Reputation: 41111
What is happening here is that because the specified tag doesn't exist, it will be created with the release. This causes a tagged pipeline to run (just as if you created the tag and pushed it).
If you just want to ignore tag pipelines, you can use a workflow rule to exclude them:
workflow:
rules:
- if: $CI_COMMIT_TAG
when: never # ignore pipelines for tags
- when: always # run the pipeline otherwise
Upvotes: 2