Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vercel cli has not option to update existing values #11130

Closed
bombillazo opened this issue Feb 7, 2024 · 6 comments · Fixed by #11348
Closed

vercel cli has not option to update existing values #11130

bombillazo opened this issue Feb 7, 2024 · 6 comments · Fixed by #11348

Comments

@bombillazo
Copy link

Hello. We use the vercel cli in our CICD platform and we've noticed that using vercel env add command will fail one existing secrets. It would be ideal if the CLI had an --update flag to make the vercel CLI overwrite the existing env secret rather than failing with an error. This will ensure we set the most recent secrets and not keeping around any old values.

@hussamkhatib
Copy link

While not ideal, you could remove the env variable vercel env rm and then add the new value.

@bombillazo
Copy link
Author

We've programmed some commands for that, but its not ideal and introduces more room for errors and intermediate states if something fails. A simple update flag would be the best way to handle it for our case.

@mountainash
Copy link
Contributor

I also have the same problem... it would be great is there was a --yes argument (that is also used on env pull and env rm to skip the confirmation/warning that the variable already exists.

@mountainash
Copy link
Contributor

mountainash commented Mar 29, 2024

I started looking into raising a PR to add this functionality and found that the Vercel API endpoint for create does allow for overriding if the KEY already exists with an upsert param.

There is also (for interest) another endpoint for "editing" an existing env var when it exists, but you need to know it's ID, not the envvar name/key (so you need to do a map first.

So it shouldn't be too much extra to change this in Vercel CLI.

@mountainash
Copy link
Contributor

mountainash commented Mar 29, 2024

What's interesting/strange/confusing is that when you attempt to vercel env add with an existing key, the CLI error is:

Error: Another Environment Variable with the same Name and Environment exists in your project. Remove it or choose a different Name or Environment.

Yet, I can't find this error message in the CLI codebase (this project), I thought maybe the API is returning this error, yet trying to create a new envar Key that already exists returns the following error from the API (https://api.vercel.com/v10/projects/${projectID}/env):

{
  "error": {
    "code": "ENV_CONFLICT",
    "message": "A variable with the name `API_URL` and target `preview` already exists",
    "key": "key",
    "envVarKey": "API_URL"
  },
  "failed": [
    {
      "error": {
        "code": "ENV_CONFLICT",
        "message": "A variable with the name `API_URL` and target `preview` already exists",
        "key": "key",
        "envVarKey": "API_URL"
      }
    }
  ]
}

I'll keep digging to see where the CLI's error is coming from (could be using an older endpoint)...

Update

Endpoint v9 is returning the error below when trying to set an existing env Key. v9 also doesn't allow the "upsert" para... so CLI will need updating to use v10 of this endpoint.

{
  "error": {
    "code": "ENV_ALREADY_EXISTS",
    "message": "Another Environment Variable with the same Name and Environment exists in your project. Remove it or choose a different Name or Environment.",
    "key": "API_URL",
    "configurationId": null,
    "target": [
      "preview"
    ]
  }
}

Update 2

CLI is using v8:
const url = /v8/projects/${projectId}/env;

mountainash added a commit to mountainash/fork-vercel-cli that referenced this issue Mar 29, 2024
@kodiakhq kodiakhq bot closed this as completed in #11348 Apr 10, 2024
kodiakhq bot pushed a commit that referenced this issue Apr 10, 2024
## Why

Closes #11130

## Changelog

Added `--force` argument to upsert existing environment variables (#11130)

## References

- Vercel API `/v10/projects/{idOrName}/env` https://vercel.com/docs/rest-api/endpoints/projects#create-one-or-more-environment-variables
@bombillazo
Copy link
Author

Awesome work!

TooTallNate pushed a commit that referenced this issue Apr 10, 2024
## Why

Closes #11130

## Changelog

Added `--force` argument to upsert existing environment variables (#11130)

## References

- Vercel API `/v10/projects/{idOrName}/env` https://vercel.com/docs/rest-api/endpoints/projects#create-one-or-more-environment-variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants