1

I have an Azure CLI task which references a PowerShell script (via build artifact) running az commands. Most of these commands work successfully, but when attempting to execute the following command:

az appconfig kv import --name $resourceName -s file --path appconfig.json --format json

I've noticed that the information was not present against the Azure resource and the log file has "File is not available".

I must be referencing the file incorrectly from the build artifact but if anyone could provide some clarity around this that would be great.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
confused-nerd
  • 47
  • 1
  • 6
  • Do you add `$(System.ArtifactsDirectory)/xxx` to the path? `System.ArtifactsDirectory`: The directory to which artifacts are downloaded during deployment of a release. In addition , you can set `system.debug=true` to get more detailed log and share the error message here. – Hugh Lin Jul 30 '20 at 10:07
  • Not get your latest information, is the workaround helpful for you? Or if you have any concern, feel free to share it here. – Hugh Lin Aug 03 '20 at 08:21
  • apologies on the delayed response I had tried a few different values last one was System.DefaultWorkingDirectory – PuffTMD Aug 11 '20 at 10:27
  • @HughLin-MSFT how/where do you add "system.debug=true" – confused-nerd Nov 27 '20 at 21:36

2 Answers2

0

I must be referencing the file incorrectly from the build artifact

You can try to add $(System.ArtifactsDirectory) to the json file path. For example: --path $(System.ArtifactsDirectory)/appconfig.json.

System.ArtifactsDirectory: The directory to which artifacts are downloaded during deployment of a release. Example: C:\agent\_work\r1\a

For details ,please refer to predefined variables .

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
0

This can be a little tricky to figure out.

System.ArtifactsDirectory is the default variable that indicates the directory to which artifacts are downloaded during deployment of a release.

However, to use a default variable in your script, you must first replace the . in the default variable names with _. For example, to print the value of artifact variable System.ArtifactsDirectory in a PowerShell script, you would have to use $env:SYSTEM_ARTIFACTSDIRECTORY.

I have a similar setup and do it this way within my PowerShell script:

# Define the path to the file
$appSettingsFile="$env:SYSTEM_ARTIFACTSDIRECTORY\<rest_of_the_path>\appconfig.json"

# Pass it to the Azure CLI command
az appconfig kv import -n $appConfigName -s file --path $appSettingsFile --format json --separator . --yes

It is also helpful to view the current values of all variables to see what they contain before using them.

References:

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30