Warm tip: This article is reproduced from serverfault.com, please click

Azure DevOps Pipeline AZ CLI upload-batch not pushing files

发布于 2020-11-30 16:45:42

I am trying to stand up a simple CI/CD process for our single page React application. The CI has been set up to npm build the React application and publish the build archive (.zip) to the $(Build.ArtifactStagingDirectory).

enter image description here

enter image description here

The CD process is then triggered to extract the build from the artifact .zip file and utilize the AZ CLI task to push the files to the Azure Blob Storage account hosting the static website.

enter image description here

enter image description here

The deployment completes successfully, however no files are published to the blob storage account. I was assuming that it had something to do with the --source flag of the AZ CLI command and tried to utilize the $(Build.DefaultWorkingDirectory)/$(Build.BuildId) environment varialbe as the source.

enter image description here

This however caused the deployment to fail with the following error.

The term 'Build.DefaultWorkingDirectory' is not recognized as the name of a cmdlet

I am unsure of how the DevOps directories are structured or how the AZ CLI interacts with them via the --source flag but any tips or suggestions would be greatly appreciated.

Questioner
jamesamuir
Viewed
11
Kevin Lu-MSFT 2020-12-01 10:38:33

The term 'Build.DefaultWorkingDirectory' is not recognized as the name of a cmdlet

Since you are using CD Process to start azure cli deployment, it seems that you are using the Release Pipeline.

Based on my test, I could reproduce this issue in Release Pipeline.

The root cause of this issue is that the variable Build.DefaultWorkingDirectory couldn't be used in Release Pipeline.

This variable only could be used in Build Pipeline(CI Process).

To solve this issue, you could try to use the variable:$(system.DefaultWorkingDirectory) .

Extract files Task

enter image description here

Azure CLI script sample:

az storage blob upload-batch --account-name $(Name) --account-key $(key) -s $(system.DefaultWorkingDirectory)/$(build.buildid) --pattern * -d xxx

Here is a Doc about the variables in Release Pipeline.

On the other hand, in addition to Azure Cli scripts, you can also directly use Azure file copy task. It will be more convenient.