![](/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.