Skip to content

Reference a shared variable with apify env link #1648

Backlog

Description

@DaveHanns

apify env link makes an env var of an Actor version reference a shared variable. A reference holds the name of the shared variable (sharedEnvVarName) in place of a value, and the platform reads the value when a run starts. apify env ls, set, and rm have to handle references too: without this change, they treat one as a plain variable with an empty value.

Scope

  • Add apify env link <stored name> [--as <name>], which makes the Actor version reference a shared variable. <stored name> is the name of the shared variable. --as sets the name of the env var on the Actor version, and it defaults to the stored name. The command picks the Actor and the version like the other apify env commands (--dir, --actor, and --version).
  • Create the env var, or update it when the version already has one of that name, as apify env set does. Say in the output when the command replaced the env var's own value (a value stored on the version itself) or pointed an existing reference to another shared variable.
  • Leave the checks to the API (apify/apify-core#32550): the shared variable has to exist in the store of the account that owns the Actor, and the caller has to be allowed to list that store. Print the API's error.
  • Mark references in apify env ls. Show the name of the shared variable in place of a value, in the table and in the --json output. Don't show a reference as plain or secret: a reference entry always has isSecret: false, and the type belongs to the shared variable.
  • Remove a reference with apify env rm <name>, like any other env var. Say in the prompt and in the result that the command removes the reference and that the shared variable stays.
  • Handle apify env set <name> on a reference: the env var then holds a value of its own in place of the reference. For other existing variables, the command keeps the type of the entry. Don't do that for a reference, or the new value would be stored as plain. Proposed: the value becomes a secret unless --no-secret is passed. Say in the result that a reference was replaced.
  • Print the rebuild reminder (printRebuildReminder in src/lib/env-vars/output.ts) after apify env link, as after a change of an env var's own value. Runs read their env var list from the build, so a reference that is added, removed, or pointed to another variable needs one rebuild. apify env rm prints the reminder already. After link, add that a later change of the shared variable's value needs no rebuild. After rm of a reference, add that runs need the shared variable until that rebuild.
  • Register the command in src/commands/env/_index.ts and in the reference generator (scripts/generate-cli-docs.ts), and describe it in the env var guide (docs/vars.md).

This can ship as two pull requests: link and the marks in ls first, then rm and set on a reference.

Rollout

The API accepts a reference only when the shared variable exists, and no variable can exist in an account without the feature flag of the store. The command needs no feature flag of its own. Release it only after resolution is in production (apify/apify-core#32552, apify/apify-core#33717).

Done when

  • Local tests (test/local/commands/env/) cover link with and without --as, over an env var with its own value, over another reference, and with an error from the API.
  • Local tests cover ls with a reference, rm of a reference, and set on a reference with and without a type flag.
  • link and rm of a reference print the rebuild reminder.

Depends on

  • The store commands and the client release they need (Manage the shared store with apify env #1580)
  • Resolution of references at run start (apify/apify-core#32552), in production before this command is released
  • Resolution of references at build start (apify/apify-core#33717), in production before this command is released

Activity

  1. added
    t-builders
    on Nov 30, 2026
  2. added theissue type on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    t-builders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions