Artifacts Filename Cannot Be Set with Dynamic Variables

Problem to solve

Core Issue: GitLab CI artifact names only support predefined CI variables like $CI_BUILD_ID but cannot use custom environment variables created during job execution like variables set in before_script or script).

What Works:

yamlartifacts:
  name: "MyName_$CI_BUILD_ID"  # ✅ Results in: MyName_123.zip

What Doesn't Work:

yamlbefore_script:
  - export MY_ENV=SomeVal
artifacts:
  name: "MyName_$MY_ENV"  # ❌ Results in: MyName_.zip (should be MyName_SomeVal.zip)

Why This is Needed:

Include project version from build tools (Gradle, Maven, etc.) without maintaining duplicate version info Add timestamps or other dynamic information to artifact names Use custom variables for better artifact organization and identification

**Current Limitation: **

  • Artifact names are processed before job execution, so runtime environment variables aren't available for expansion. Proposed Solutions:

Primary: Expand artifact names on GitLab server side with security checks to prevent sensitive credential exposure in filenames Alternative: Send YAML-defined variables to Runner for processing

Use Cases:

  • Gradle/Maven project versions in artifact names
  • Timestamps for build identification
  • Any custom metadata that's determined during build execution

The issue prevents users from creating meaningful, dynamic artifact names based on build-time information.

Original Comment thread

Since merge request !113 (merged) it is possible to define artifact names even with variables like that:

build:
  stage: build
  script:
    - ./someBuildScript
  artifacts:
    name: "MyName_$CI_BUILD_ID"
    paths:
      - some/artifacts/*.jar

The script above results in an artifacts file like that: MyName_123.zip

But it is not possible to use dynamically created environment variables like that:

before_script:
  - export MY_ENV=SomeVal
build:
  stage: build
  script:
    - ./someBuildScript
  artifacts:
    name: "MyName_$MY_ENV"
    paths:
      - some/artifacts/*.jar

The script above results in an artifacts file like that: MyName_.zip but desired is MyName_SomeVal.zip.

Why is this desired?

Currently there is no way to provide the artifacts archive name with custom information, except those things that are already available by predefined CI variables or global static variables. In my case I would like to add the project version of my gradle project. I don't want to maintain the version in two files because this is error prone.

Others might want the current time stamp in the name or something else.

Versions

  • gitlab-ci-multi-runner => 1.5.2
  • GitLab 8.10.6

Proposal

We have 2 options that needs to be evaluated before taking a decision.

Primary Proposal

  1. Expand artifacts:name in the GitLab side and send it to Runner

    We need to have a backend check to make sure the artifact name expansion isn't expanding a CI variable that may have a sensitive credential and the artifact name after expansion doesn't have a sensitive credential in it (for example, artifact-gl-pat-...).

Alternative Proposal - To be evaluated

  1. Send YAML-defined variables to Runner
Edited by Darren Eastman