[英]bash if statement inside the azure devops task is not executing
I was trying to automate azure filesystem and directory creation inside an existing storage account if they are not existing already.我试图在现有存储帐户中自动创建 azure 文件系统和目录,如果它们不存在的话。 I am using Azure devops pipeline task for this.
我为此使用 Azure devops 管道任务。 Tried below inline script in both "bash" and "azurecli" tasks inside the Azuredevops pipeline.
在 Azuredevops 管道内的“bash”和“azurecli”任务中尝试以下内联脚本。 But its failing to check the existance of blob or files in the containers and simply passing the tasks without giving any error, but its not creating any resource either.
但它未能检查容器中是否存在 blob 或文件,只是简单地传递任务而不给出任何错误,但它也没有创建任何资源。 here all those parameters are properly defined as runtinme parameters within the yaml.
在这里,所有这些参数都正确定义为 yaml 中的运行参数。 Seems some issue with the bash script i am using
我正在使用的 bash 脚本似乎有些问题
- task: AzureCLI@2
displayName: 'create the filesystem ${{parameters.fsname}} & parent directory ${{parameters.parentdirectory}} if not exists'
inputs:
azureSubscription: ${{parameters.subscription}}
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
existing_fs=$(az storage fs exists -n ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login)|cut -d : -f 2 | sed 's/.//'
existing_directory=$(az storage fs directory exists -n ${{parameters.parentdirectory}} -f ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login)|cut -d : -f 2 | sed 's/.//'
if [ "$existing_fs" = false ]; then
az storage fs create -n ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login
fi
if [ "$existing_directory" = false ]; then
az storage fs directory create -n ${{parameters.parentdirectory}} -f ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login
fi
I have tested in my environment.我已经在我的环境中测试过了。
if statement inside the azure devops task is not executing because the variables existing_fs and existing_directory are different from false. azure devops 任务中的 if 语句未执行,因为变量 existing_fs 和 existing_directory 不同于 false。
You can use powershell script instead of bash script.您可以使用 powershell 脚本代替 bash 脚本。
And the inline script can be as follows:并且内联脚本可以如下:
$existing_fs=(az storage fs exists -n ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login | ConvertFrom-Json).exists
$existing_directory=(az storage fs directory exists -n ${{parameters.parentdirectory}} -f ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login | ConvertFrom-Json).exists
if (!$existing_fs)
az storage fs create -n ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login
if (!$existing_directory)
az storage fs directory create -n ${{parameters.parentdirectory}} -f ${{parameters.fsname}} --account-name ${{parameters.storagename}} --auth-mode login
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.