我有一个.ps1文件,我在其中编写了Azure CLI脚本以使用服务主体登录到Azure。
write-host 'Login start'
#parameters
$applicationId = $args[0].toString()
$securePasswordSP = $args[1].toString()
$tenantId = $args[2].toString()
$adminSecurePassword = $securePasswordSP | ConvertTo-SecureString -AsPlainText -Force
az login --service-principal --username $applicationId --password $adminSecurePassword --tenant $tenantId
write-host 'Login end'
此文件放置在“ C:\ Test”路径中。因此,我打开了Powershell来执行此文件。我运行以下命令。
$SpId = "Service principal Id"
$SpSecret = "Sp Secret"
$tenantId = "Tenant Id"
& "C:\Test\TestScript.ps1" $SpId $SpSecret $tenantId
这完全符合预期,并且我能够登录到Azure帐户。
但是当我使用相同的命令从Bamboo运行时,它不起作用。在Bamboo中,我添加了一个阶段-> Job。在这项工作中,我添加了一个任务。我选择了以下内容:
Task Type : Script Configuration
Interpreter : Windows Powershell
Script location : Inline
Script Body :
$SpId = "Service principal Id"
$SpSecret = "Sp Secret"
$tenantId = "Tenant Id"
& "C:\Test\TestScript.ps1" $SpId $SpSecret $tenantId
运行此作业时,出现以下错误。
az : The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
当我直接在Bamboo Agent中打开Windows Powershell并运行相同的命令时,它正在工作。但是,当我从Bamboo门户网站运行相同的命令时,它失败了。我还缺少其他步骤吗?
我们非常感谢您的帮助。