Azure / Azure/azure-cli

Azure Devops pipeline fails intermittently when trying to create a new variable in variable group using "az pipelines variable-group variable create"

Open
#29,803 2 comments 0 reactions 0 assignees View on GitHub
act-platform-engineering-squad Auto-Assign bug customer-reported DevOps Pipelines Service Attention
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

One of the tasks in our pipeline is to create a new variable in a variable group

```
- script: |
az extension add --name azure-devops --allow-preview false
az pipelines variable-group variable create --group-id 481 --org "https://dev.azure.com/dwc/" --project "Test" --name $(tag) --value $(outputId)
displayName: "Save output id to variable"
env:
AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
```

The task fails with the following error

### Related command

```
az extension add --name azure-devops --allow-preview false
az pipelines variable-group variable create
```

### Errors

```
ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: 'NoneType' object has no attribute 'keys'
Traceback (most recent call last):
File "/opt/az/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
raise ex
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 723, in _run_job
return cmd_copy.exception_handler(ex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/exception_handler.py", line 31, in azure_devops_exception_handler
reraise(*sys.exc_info())
File "/opt/az/lib/python3.11/site-packages/six.py", line 719, in reraise
raise value
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
result = cmd_copy(params)
^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
return self.handler(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
^^^^^^^^^^^^^^^^^^
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/pipelines/variable_group.py", line 182, in variable_group_variable_add
for key in var_group.variables.keys():
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'keys'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

```

### Issue script & Debug output

```
ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: 'NoneType' object has no attribute 'keys'
Traceback (most recent call last):
File "/opt/az/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
raise ex
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 723, in _run_job
return cmd_copy.exception_handler(ex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/common/exception_handler.py", line 31, in azure_devops_exception_handler
reraise(*sys.exc_info())
File "/opt/az/lib/python3.11/site-packages/six.py", line 719, in reraise
raise value
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 701, in _run_job
result = cmd_copy(params)
^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 334, in __call__
return self.handler(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
return op(**command_args)
^^^^^^^^^^^^^^^^^^
File "/root/.azure/cliextensions/azure-devops/azext_devops/dev/pipelines/variable_group.py", line 182, in variable_group_variable_add
for key in var_group.variables.keys():
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'keys'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

```

### Expected behavior

Should not fail

### Environment Summary

N/A

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.