![](/img/trans.png)
[英]Logic App JSON file could not be update through Azure CLI Command using Azure Release Pipeline
[英]Bitbucket pipeline to deploy to Azure VM using Azure-cli command cannot access to script file
我的源代碼在 Bitbucket 中,我正在使用 bitbucket 管道構建我的 Web 應用程序並將其部署到 Azure VM。
由於限制使用第三方工具,我沒有使用 Azure Web 應用程序。
我堅持如何在我的 Azure cli 運行命令中使用腳本文件。
實際錯誤是:
"/opt/atlassian/pipelines/agent/build/SetupSimpleSite.ps1 : The term \n'/opt/atlassian/pipelines/agent/build/SetupSimpleSite.ps1' is not recognized as the name of a cmdlet, function, script \nfile, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct \nand try again.\nAt C:\\Packages\\Plugins\\Microsoft.CPlat.Core.RunCommandWindows\\1.1.8\\Downloads\\script1.ps1:1 char:1\n+ /opt/atlassian/pipelines/agent/build/SetupSimpleSite.ps1
我的管道代碼:
test-azure-cli-pipeline:
- step:
name: "Display Azure account"
deployment: staging
script:
- pipe: microsoft/azure-cli-run:1.1.0
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
#CLI_COMMAND: 'az account show'
CLI_COMMAND: 'az vm run-command invoke --command-id RunPowerShellScript --name $AZURE_VM_NAME --resource-group $AZURE_RESOURCE_GROUP_NAME --scripts $BITBUCKET_CLONE_DIR/SetupSimpleSite.ps1'
腳本 SetupSimpleSite.ps1 位於我的 Git 存儲庫的根目錄下,與我的 bitbucket-pipelines.yml 目錄相同
請注意,Azure cli 工作正常,因為 az account show 正在按預期顯示帳戶詳細信息。
我無法從存儲庫中找到有關如何使用 azure cli 源代碼腳本的任何相關信息,鏈接: https://bitbucket.org/microsoft/azure-cli-run/src/master/
我希望我的腳本 Powershell 保留在我的源代碼中。
我終於讓它工作了,你應該在文件前加上“@”。
我從那里找到了解決方案: Using the 'az vm run-command' with a.ps1 file
所以這是最終的腳本工作:
test-azure-cli-pipeline:
- step:
name: "Display Azure account"
deployment: staging
script:
- pipe: microsoft/azure-cli-run:1.1.0
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
CLI_COMMAND: 'az vm run-command invoke --command-id RunPowerShellScript --name $AZURE_VM_NAME --resource-group $AZURE_RESOURCE_GROUP_NAME --scripts @SetupSimpleSite.ps1'
DEBUG: 'true'
調試 true 很有用,感謝 Chase
首先添加DEBUG: 'true'
還添加了pwd; ls;
pwd; ls;
到您的 CLI_COMAND 驗證您的路徑是否正確,這是您收到的錯誤,因此最有可能是問題所在。 修復路徑並再次測試。
test-azure-cli-pipeline:
- step:
name: "Display Azure account"
deployment: staging
script:
- pipe: microsoft/azure-cli-run:1.1.0
variables:
AZURE_APP_ID: $AZURE_APP_ID
AZURE_PASSWORD: $AZURE_PASSWORD
AZURE_TENANT_ID: $AZURE_TENANT_ID
CLI_COMMAND: 'pwd ; ls ; az vm run-command invoke --command-id RunPowerShellScript --name $AZURE_VM_NAME --resource-group $AZURE_RESOURCE_GROUP_NAME --scripts $BITBUCKET_CLONE_DIR/SetupSimpleSite.ps1'
DEBUG: 'true'
如果這不起作用,請停止使用 azure-cli-pipe,而是使用 az-cli docker 圖像的步驟: mcr.microsoft.com/azure-cli
並作為常規腳本運行...(我不是熟悉 az cli 以了解如何配置憑據,但您應該知道。)
- step:
name: Run AZ script
image: mcr.microsoft.com/azure-cli
script:
- az login -u $AZURE_APP_ID -p $AZURE_PASSWORD #setup az credentials
- az vm run-command invoke --command-id RunPowerShellScript --name $AZURE_VM_NAME --resource-group $AZURE_RESOURCE_GROUP_NAME --scripts $BITBUCKET_CLONE_DIR/SetupSimpleSite.ps1'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.