bitbucket - 使用 Azure-cli 命令部署到 Azure VM 的 Bitbucket 管道无法访问脚本文件
问题描述
我在 Bitbucket 中有我的源代码,我正在使用 bitbucket 管道来构建我的 Web 应用程序并将其部署到 Azure VM。
由于限制使用第三方工具,我没有使用 Azure Web 应用程序。
我被困在如何在我的 Azure cli run 命令中使用脚本文件。
实际错误是:
"/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'
debug true 很有用,谢谢 Chase
推荐阅读
- java - 如何为对象(minIO)设置生命周期规则?
- snowflake-cloud-data-platform - 从雪花发送电子邮件警报
- vue.js - 将 Vuetify 添加到单个 .vue 组件
- javascript - 单击按钮时Divs不在正确的位置
- json - SQLite 中的 JSON 函数
- mongodb - Mongoose 从数组中返回一个对象
- python - 是否可以在不首先使用 GitPython(或更一般的 Git)克隆存储库的情况下检索当前 HEAD 的提交 ID?
- laravel - 如何让用户订阅计划?
- python - AttributeError:“NoneType”对象没有属性“解码”
- flutter - 未找到“未找到 X Android SDK 文件:C:\Users\smart\AppData\Local\Android\Sdk\platforms\android-30\android.jar。”