in azure-devops/azext_devops/dev/pipelines/variable_group.py [0:0]
def variable_group_variable_update(group_id, name, new_name=None, value=None, secret=None, prompt_value=False,
organization=None, project=None, detect=None):
"""Update a variable in a variable group
:param group_id: Id of the variable group.
:type group_id: int
:param name: Name of the variable.
:type name: str
:param new_name: New name of the variable.
:type new_name: str
:param value: New value of the variable. For secret variables, if --value parameter is not given,
it will be picked from environment variable prefixed with AZURE_DEVOPS_EXT_PIPELINE_VAR_ or
user will be prompted to enter it via standard input.
e.g. PersonalAccessToken can be input using environment variable AZURE_DEVOPS_EXT_PIPELINE_VAR_PersonalAccessToken
:type value: str
:param secret: If the value of the variable is a secret.
:type secret: str
:param prompt_value: Set it to True to update the value of a secret variable using
environment variable or prompt via standard input.
:type prompt_value: str
"""
if not new_name and not value and secret is None and not prompt_value:
raise CLIError('Atleast one of --new-name, --value or --is-secret, --prompt-value '
'must be specified for update.')
organization, project = resolve_instance_and_project(
detect=detect, organization=organization, project=project)
client = get_task_agent_client(organization)
var_group = client.get_variable_group(group_id=group_id, project=project)
if not var_group:
raise CLIError('Variable group with Id {} could not be found.'.format(group_id))
old_key = None
old_value = None
new_key = None
# Check if the variable already exists
old_key, old_value = _case_insensitive_get(input_dict=var_group.variables, search_key=name)
new_key = new_name if new_name else old_key
if old_key:
secret = old_value.is_secret if secret is None else secret
if not value and secret and prompt_value:
value = _get_value_from_env_or_stdin(var_name=new_key)
from azext_devops.devops_sdk.v5_0.task_agent.models import VariableValue
if old_key != new_key:
existing_key, _ = _case_insensitive_get(input_dict=var_group.variables, search_key=new_key)
if existing_key:
raise CLIError('Variable \'{}\' already exists.'.format(existing_key))
var_group.variables.pop(old_key)
var_group.variables[new_key] = VariableValue(
is_secret=secret,
value=old_value.value if value is None else value)
updated_variables = client.update_variable_group(
group=var_group, project=project, group_id=group_id).variables
var_name, var_value = _case_insensitive_get(input_dict=updated_variables, search_key=new_key)
return {var_name: var_value}
raise CLIError('Variable \'{}\' does not exist. '.format(name))