Azure / azure-devops-cli-extension

Azure DevOps Extension for Azure CLI
https://docs.microsoft.com/en-us/cli/azure/ext/azure-devops/?view=azure-cli-latest
MIT License
634 stars 242 forks source link

az artifacts universal download: File is not a zip file #1117

Open quilter-AndrewWilde opened 3 years ago

quilter-AndrewWilde commented 3 years ago

The az artifacts universal download is failing to download a universal package with error "File is not a zip file"

Command Name az artifacts universal download Extension Name: azure-devops. Version: 0.19.0.

Errors:

File is not a zip file
Traceback (most recent call last):
Lib\site-packages\knack\cli.py, ln 233, in invoke
cli\core\commands\__init__.py, ln 660, in execute
cli\core\commands\__init__.py, ln 723, in _run_jobs_serially
cli\core\commands\__init__.py, ln 715, in _run_job
...
    artifacttool_binary_path = self._get_artifacttool(organization)
azext_devops\dev\common\artifacttool_updater.py, ln 74, in _get_artifacttool
    _update_artifacttool(release_uri, release_id)
azext_devops\dev\common\artifacttool_updater.py, ln 114, in _update_artifacttool
    f = zipfile.ZipFile(content)
zipfile.py, ln 1131, in __init__
zipfile.py, ln 1198, in _RealGetContents
zipfile.BadZipFile: File is not a zip file

To Reproduce:

az artifacts universal download --organization "https://dev.azure.com/AndrewWilde0938/" --project "5863fe84-1344-4d79-b86a-ab4e41f3a8bc" --scope project --feed "uni" --name "blah" --version "0.0.6" --path .

Expected Behavior

Succesfully downloads artifact

Environment Summary

Windows-10-10.0.14393-SP0
Python 3.6.8
Installer: MSI

azure-cli 2.21.0

Extensions:
azure-devops 0.19.0

Additional Context

jmyersmsft commented 3 years ago

Is there any output before the line "File is not a zip file"? If so, could you add it?

quilter-AndrewWilde commented 3 years ago

The only output is The command failed with an unexpected error. Here is the traceback:

jmyersmsft commented 3 years ago

If you add --debug to your command line, we may get more information

Before doing that, let's try clearing out any bad state by deleting %userprofile%\.azure\cli\tools\artifacttool (%userprofile% is very likely c:\users\<username>\)

AleksandarTomicMs2 commented 2 years ago

@jmyersmsft we get this periodically in ADO pipelines - I've added the "debug" flag, and the callstacks that we get are:

...
DEBUG: urllib3.connectionpool: https://vsblob.dev.azure.com:443 "GET /EDT/_apis/clienttools/ArtifactTool/release?osName=Windows&arch=AMD64&distroName=msys_nt-10.0-20348&distroVersion=3.3.3 HTTP/1.1" 200 440
DEBUG: azext_devops.devops_sdk.client: Response content: b'{"name":"ArtifactTool","rid":"win10-x64","version":"0.2.236","uri":"https://0psvsblobprodwus2145.vsblob.vsassets.io/artifacttool/artifacttool-win10-x64-Release_0.2.236.zip?sv=2019-07-07&sr=b&sig=BR%2FU7OyJ8htI2rV6zfWijyD6n1Bz9fiPIx9rPUhUOi0%3D&spr=https&se=2022-05-16T15%3A44%3A02Z&sp=r&P1=1652715542&P2=11&P3=2&P4=0Ge7t3LzHJnQB7u5dXytpAWhzbeRGR3GBLudh2mW3EI%3d"}'
DEBUG: cli.azext_devops.dev.common.artifacttool_updater: Checking if we already have ArtifactTool release 'ArtifactTool_win10-x64_0.2.236'
DEBUG: cli.azext_devops.dev.common.artifacttool_updater: Updating to ArtifactTool release ArtifactTool_win10-x64_0.2.236 since it doesn't exist at C:\Users\VssAdministrator\.azure\azuredevops\cli\tools\artifacttool\ArtifactTool_win10-x64_0.2.236
DEBUG: cli.azext_devops.dev.common.artifacttool_updater: Downloading ArtifactTool from https://0psvsblobprodwus2145.vsblob.vsassets.io/artifacttool/artifacttool-win10-x64-Release_0.2.236.zip?sv=2019-07-07&sr=b&sig=BR%2FU7OyJ8htI2rV6zfWijyD6n1Bz9fiPIx9rPUhUOi0%3D&spr=https&se=2022-05-16T15%3A44%3A02Z&sp=r&P1=1652715542&P2=11&P3=2&P4=0Ge7t3LzHJnQB7u5dXytpAWhzbeRGR3GBLudh2mW3EI%3d
DEBUG: urllib3.connectionpool: Starting new HTTPS connection (1): 0psvsblobprodwus2145.vsblob.vsassets.io:443
DEBUG: urllib3.connectionpool: https://0psvsblobprodwus2145.vsblob.vsassets.io:443 "GET /artifacttool/artifacttool-win10-x64-Release_0.2.236.zip?sv=2019-07-07&sr=b&sig=BR%2FU7OyJ8htI2rV6zfWijyD6n1Bz9fiPIx9rPUhUOi0%3D&spr=https&se=2022-05-16T15%3A44%3A02Z&sp=r&P1=1652715542&P2=11&P3=2&P4=0Ge7t3LzHJnQB7u5dXytpAWhzbeRGR3GBLudh2mW3EI%3D HTTP/1.1" 200 65282397
DEBUG: cli.azext_devops.dev.common.artifacttool_updater: Extracting ArtifactTool to C:\Users\VssAdministrator\.azure\azuredevops\cli\tools\artifacttool\4bff4dde-8943-4d2f-a802-ddf42372528c
DEBUG: cli.azext_devops.dev.common.exception_handler: handling generic error
DEBUG: cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
DEBUG: cli.azure.cli.core.util: Traceback (most recent call last):
DEBUG: cli.azext_devops.dev.common.artifacttool_updater: Extracting ArtifactTool to C:\Users\VssAdministrator\.azure\azuredevops\cli\tools\artifacttool\4bff4dde-8943-4d2f-a802-ddf42372528c
DEBUG: cli.azext_devops.dev.common.exception_handler: handling generic error
DEBUG: cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
DEBUG: cli.azure.cli.core.util: Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 658, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 721, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 713, in _run_job
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\exception_handler.py", line 31, in azure_devops_exception_handler
    reraise(*sys.exc_info())
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\six.py", line 703, in reraise
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 692, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\artifacts\universal.py", line 98, in download_package
    return artifact_tool.download_universal(organization, project, feed, name, version, path, file_filter)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool.py", line 42, in download_universal
    return self.run_artifacttool(organization, args, "Downloading")
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool.py", line 57, in run_artifacttool
    artifacttool_dir = self._artifacttool_updater.get_latest_artifacttool(organization)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool_updater.py", line 43, in get_latest_artifacttool
    artifacttool_binary_path = self._get_artifacttool(organization)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool_updater.py", line 74, in _get_artifacttool
    _update_artifacttool(release_uri, release_id)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool_updater.py", line 114, in _update_artifacttool
    f = zipfile.ZipFile(content)
  File "zipfile.py", line 1267, in __init__
  File "zipfile.py", line 1334, in _RealGetContents
zipfile.BadZipFile: File is not a zip file

ERROR: cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
ERROR: az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
ERROR: cli.azure.cli.core.azclierror: File is not a zip file
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 658, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 721, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 713, in _run_job
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\exception_handler.py", line 31, in azure_devops_exception_handler
    reraise(*sys.exc_info())
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\six.py", line 703, in reraise
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 692, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\artifacts\universal.py", line 98, in download_package
    return artifact_tool.download_universal(organization, project, feed, name, version, path, file_filter)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool.py", line 42, in download_universal
    return self.run_artifacttool(organization, args, "Downloading")
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool.py", line 57, in run_artifacttool
    artifacttool_dir = self._artifacttool_updater.get_latest_artifacttool(organization)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool_updater.py", line 43, in get_latest_artifacttool
    artifacttool_binary_path = self._get_artifacttool(organization)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool_updater.py", line 74, in _get_artifacttool
    _update_artifacttool(release_uri, release_id)
  File "C:\Program Files\Common Files\AzureCliExtensionDirectory\azure-devops\azext_devops\dev\common\artifacttool_updater.py", line 114, in _update_artifacttool
    f = zipfile.ZipFile(content)
  File "zipfile.py", line 1267, in __init__
  File "zipfile.py", line 1334, in _RealGetContents
zipfile.BadZipFile: File is not a zip file
ERROR: az_command_data_logger: File is not a zip file
...

(I've truncated the initial logs since they are the same between successful & failed runs, so I doubt will be much use in debugging what's causing this)

Our pipeline uses Microsoft Hosted Agents, and the VMs that run the build should be fresh each time, so there shouldn't be any differences in the machine configuration between successful and failed runs.

sorinr-gh commented 1 year ago

Late to the party but I leave this here for anyone looking for an explanation.

We encountered the same error in our corporate environment and, in our case, we tracked down the problem to Zscaler which was blocking the request to get the ArtifactTool zip file (on the log above see the line _Downloading ArtifactTool from https://0psvsblobprodwus2145.vsblob.vsassets.io/artifacttool/artifacttool-win10-x64-Release_0.2.236.zip......_)