Skip to content

Add binary assets to a Release via gitlab-ci.yml

Problem to solve

In #26013 (closed) we extended gitlab-ci.yml to support the creation of Releases automatically by a pipeline.

This issue extends that functionality by adding support for attaching binary assets to Releases during pipeline creation, defined by gitlab-ci.yml

Intended users

Automation engineers who are working on releases and want a native way to add releases without using script: elements to curl an API.

Further details

This will require coordination between the Release, Runner and Packing teams.

Additional considerations:

  • Do we allow for changes to releases
  • Integration with Release Evidence
  • Automatic creation of tags if they do not exist

Proposal

stages:
  - build
  - upload
  - release
  
variables:
  DARWIN_AMD64_BINARY: "myawesomerelease-darwin-amd64-${CI_COMMIT_TAG}"
  LINUX_AMD64_BINARY: "myawesomerelease-linux-amd64-${CI_COMMIT_TAG}"
  PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/myawesomerelease/${CI_COMMIT_TAG}/"

build:
  stage: build
  image: alpine:latest
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - mkdir bin
    - echo "Mock binary for ${DARWIN_AMD64_BINARY}" > bin/${DARWIN_AMD64_BINARY}
    - echo "Mock binary for ${LINUX_AMD64_BINARY}" > bin/${LINUX_AMD64_BINARY}
  artifacts:
    paths:
      - bin/

upload:
  stage: upload
  image: curlimages/curl:latest
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - |
      curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/${DARWIN_AMD64_BINARY} ${PACKAGE_REGISTRY_URL}
    - |
      curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/${LINUX_AMD64_BINARY} ${PACKAGE_REGISTRY_URL}

release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:v0.4.0
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - |
      release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
        --assets-link "{\"name\":\"${DARWIN_AMD64_BINARY}\",\"url\":\"${PACKAGE_REGISTRY_URL}${DARWIN_AMD64_BINARY}\"}" \
        --assets-link "{\"name\":\"${LINUX_AMD64_BINARY}\",\"url\":\"${PACKAGE_REGISTRY_URL}${LINUX_AMD64_BINARY}\"}"

Create a custom package registry for binary assets

As described in:

#208712 (closed)

Extend the Releaser CLI

  • modify the Releaser CLI to make the API calls for binary assets
  • optionally the Releaser could orchestrate between the Runner, the new package registry and Rails.

As described in release-cli#41 (closed)

Documentation

Extend documentation produced here !19237 (merged)

What is the type of buyer?

This feature will be available on all tiers.

Links / references

Edited by Jackie Porter