尝试获取在Artifacts Run Powershell脚本中使用的开发人员测试实验室VM用户名

问题描述

我们创建了人工制品 “克隆Git存储库”-从git hub克隆PS1脚本 “运行Powershell”运行PS1脚本。 这些工件链接到Formulae。

在创建新VM时,将应用公式运行以运行PS1脚本。 公式运行后,尝试使用下面的powershell ps1脚本发送邮件

PS1脚本

STATIC_URL = '/static/'
STATIC_ROOT= os.path.join(BASE_DIR,"static","static_root")

STATICFILES_Dirs = [
    os.path.join(BASE_DIR,"static"),]

我很累,但是脚本无法发送消息可能是因为... ... ##Send mail to the User email $ipV4 = Test-Connection -ComputerName (hostname) -Count 1 | Select -ExpandProperty IPV4Address $emailId = $env:UserName+"@gmail.com" $body = "<html> <body> Hi $emailId,</br> </br> Your VM $ipV4 is ready to access. <br/> Thanks,</br> Digital Engagement Team </body> </html>" Send-MailMessage -To $emailId -from *** -Subject "Azure VM $ipV4 is Ready" -SmtpServer ****** -port 25 -Body $body -BodyAsHtml 无效。如何获取VM用户名作为PS1的参数,以便我可以附加gmail.com并发送?

解决方法

您可能需要使其大写以使其能够找到变量。查看文档accessing variables through the environment:

请注意,变量也可以通过以下方式提供给脚本 环境变量。使用这些环境的语法 变量取决于脚本语言。

名称为大写,并且为。替换为_。这是 自动插入到流程环境中。这里有一些 例子:

  • 批处理脚本:%VARIABLE_NAME%
  • PowerShell脚本:$ env:VARIABLE_NAME
  • bash脚本:$ VARIABLE_NAME