Search code examples
windowsiisazure-devopsazure-pipelinesrelease

Cross-post from DevOps: Azure Release Pipeline Fails Using Expand-Archive Command


Cross-posted from https://devops.stackexchange.com/questions/13583/azure-release-pipeline-fails-using-expand-archive-command as there has been zero activity there :(.

Sometime in the last week, our pipeline started using Expand-Archive to open the .zip file during the "IIS Web App Deployment" step instead of 7-Zip. It does not appear that this was done by our team, so I'm presuming this may have been changed in DevOps.

We are deploying to Server 2012R2.

Several of our apps are okay with this, however one of them fails to expand. It seems as if this might be related to path length (this app uses some very deep folder nesting with Angular) since I can manually run the command successfully if I shorten the destination path.

The command that fails to runs on the server is:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command "Expand-Archive -Path "C:\azagent\A3\_work\r1\a\thisistheazurejobname\drop\thisisourappsnamex.zip" -DestinationPath "C:\azagent\A3\_work\_temp\temp_web_package_8157628602055582" -Force"

If I reduce it to:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command "Expand-Archive -Path "C:\azagent\A3\_work\r1\a\thisistheazurejobname\drop\thisisourappsnamex.zip" -DestinationPath "C:\azagent\A3\_work\_temp\short" -Force"

...it appears to work fine.

Obviously, I am speculating that it's a path-length issue, but evidence does seem to support it. Also, I reconstructed what would have been the 7-Zip command and it worked as expected:

C:\azagent\A3\_work\_tasks\IISWebAppDeploymentOnMachineGroup_1b467810-6725-4b6d-accd-886174c09bba\0.184.0\node_modules\webdeployment-common-v2\7zip\7z.exe x -oC:\azagent\A3\_work\_temp\temp_web_package_8157628602055582 C:\azagent\A3\_work\r1\a\thisistheazurejobname\drop\thisisourappsnamex.zip

I looked at the advice here and found we are already using the setting: https://igorpuhalo.wordpress.com/2019/08/29/overcoming-long-path-problem-in-powershell/

My hope is that someone knows what may have changed, can suggest a straightforward way to go back to using 7-Zip, or a way to make Expand-Archive to work.


Solution

  • The Expand-Archive command in IIS Web App Deployment task is run by this task by default. We couldn't change the command to use 7-Zip in this tasks.

    Here is the Task source code. It will use Powershell.

    can suggest a straightforward way to go back to using 7-Zip, or a way to make Expand-Archive to work.

    You could try the following two methods to change to use 7-zip or make the command work:

    1.To use 7-zip, you need to convert the steps of IIS web deploy into a Command Line Task.

    Here are the steps:

    In the Release Log , you could see the Expand-Archive command and the msdeploy command.

    enter image description here

    You could copy these two command to Command Line task and change the -source parameterms to the zip package path in deploy command.

    for example:

    "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"   -verb:sync -source:package='C:\azagent\A4\_work\r32\a\_TEST PROJECT-ASP.NET Core (.NET Framework)-CI (82)\drop\WebApp.zip' -dest:auto -setParam:name='IIS Web Application Name',value='kevin0322' -enableRule:AppOffline -enableRule:DoNotDeleteRule
    

    Then you could use the 7-Zip command to replace the first Powershell command.

    2.You could use Powershell 7 instead of Powershell\v1.0.

    Here is the doc about installing powershell 7

    Powershell 7 has more powerful features. Refer to this ticket.

    After installing Powershell 7 and set the system environment, the task will use Powershell 7 .

    enter image description here

    To set system env, you could navigate to system -> Environment variables.

    enter image description here