Skip to content

Instantly share code, notes, and snippets.

@leohilbert
Created October 28, 2020 09:48
Show Gist options
  • Save leohilbert/7c0436ea51691f18fefa4822c1067d4b to your computer and use it in GitHub Desktop.
Save leohilbert/7c0436ea51691f18fefa4822c1067d4b to your computer and use it in GitHub Desktop.
delete gitlab-tag, create a new one, upload an artifact, create a new release and attach the artifact to it.
upload_next:
stage: deploy
when: manual
except:
refs:
- next
only:
- master
needs: [ "package" ]
dependencies: [ "package" ]
image: registry.gitlab.com/gitlab-org/release-cli
variables:
GITLAB_URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST"
script:
- apk add curl zip jq
- (cd compiled && zip -rq ../next-$CI_COMMIT_SHORT_SHA.zip .)
- >
export UPLOAD_RESPONSE=$(curl --request POST -s -H "PRIVATE-TOKEN: $GITLAB_API_TOKEN"
--form "file=@next-$CI_COMMIT_SHORT_SHA.zip"
"$GITLAB_URL/api/v4/projects/$CI_PROJECT_ID/uploads")
- echo $UPLOAD_RESPONSE
- export PACKAGE_PATH=$(echo "$UPLOAD_RESPONSE" | jq -r '.full_path')
- >
curl --request DELETE -H "PRIVATE-TOKEN: $GITLAB_API_TOKEN"
"$GITLAB_URL/api/v4/projects/$CI_PROJECT_ID/repository/tags/next"
- echo "$GITLAB_URL$PACKAGE_PATH"
- >
release-cli create --name next --description next --tag-name next --ref $CI_COMMIT_SHA
--assets-link $(echo '{"name":"package","url":"'"$GITLAB_URL$PACKAGE_PATH"'","link_type":"package"}')
@leohilbert
Copy link
Author

leohilbert commented Oct 28, 2020

Because of https://gitlab.com/gitlab-org/gitlab/-/issues/24155 this is useless right now, but I wanted to persist it somewhere 😭
Once the API exists you could get the attached URL like this:

PROJECT_NAME=$(curl -s -H "PRIVATE-TOKEN: $GITLAB_API_TOKEN" $PROJECT_URL | jq -r '.name')
PACKAGE_LINK=$(curl -s -H "PRIVATE-TOKEN: $GITLAB_API_TOKEN" $PROJECT_URL/releases/next | jq -r '.assets.links[] | select (.name=="package") | .url')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment