[英]File path from within Azure CLI task
I have an Azure CLI task which references a PowerShell script (via build artifact) running az
commands.我有一个 Azure CLI 任务,它引用了运行
az
命令的 PowerShell 脚本(通过构建工件)。 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".我注意到没有针对 Azure 资源的信息,并且日志文件具有“文件不可用”。
I must be referencing the file incorrectly from the build artifact but if anyone could provide some clarity around this that would be great.我一定是从构建工件中错误地引用了该文件,但是如果有人可以对此提供一些清晰的说明,那就太好了。
I must be referencing the file incorrectly from the build artifact
我必须从构建工件中错误地引用文件
You can try to add $(System.ArtifactsDirectory)
to the json file path.您可以尝试将
$(System.ArtifactsDirectory)
添加到 json 文件路径中。 For example: --path $(System.ArtifactsDirectory)/appconfig.json
.例如:
--path $(System.ArtifactsDirectory)/appconfig.json
。
System.ArtifactsDirectory
: The directory to which artifacts are downloaded during deployment of a release. System.ArtifactsDirectory
:在发布部署期间将工件下载到的目录。 Example: C:\agent\_work\r1\a
示例:
C:\agent\_work\r1\a
For details,please refer to predefined variables .有关详细信息,请参阅预定义变量。
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. System.ArtifactsDirectory
是默认变量,它指示在发布部署期间将工件下载到的目录。
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
.例如,要在 PowerShell 脚本中打印工件变量
System.ArtifactsDirectory
的值,您必须使用$env:SYSTEM_ARTIFACTSDIRECTORY
。
I have a similar setup and do it this way within my PowerShell script:我有一个类似的设置,并在我的 PowerShell 脚本中这样做:
# 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:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.