英文:
Env variable not being recognized
问题
CICD: Azure DevOps
任务:Azure CLI
脚本位置:内联脚本
任务版本:1
代理:自托管
语言:Go
当我从Azure Pipeline传递环境变量时,我遇到了一个奇怪的问题。
命令(内联脚本):
$env:ENV="FOO"
输出:
2021-09-03T13:49:28.9213455Z
2021-09-03T13:49:28.9214265Z c:\Agent\_work\r1\a>$env:ENV="FOO"
**2021-09-03T13:49:28.9219788Z 文件名、目录名或卷标语法不正确。**
2021-09-03T13:49:28.9298991Z ##[error]脚本执行失败:错误:进程 'c:\Agent\_work\_temp\azureclitaskscript1630676963575.bat' 以退出代码 1 失败
相同的命令在本地虚拟机的 PowerShell 中完全正常工作,但不知道为什么在 Pipeline 中不起作用。有什么建议吗?
注意:目录路径是正确的。
英文:
CICD: Azure devOps
Task: Azure CLI
Script Location: Inline Script
Task Version: 1
Agent: Self-hosted
Language: Go
I am facing a strange issue when I pass the env variable from Azure Pipeline.
Command (Inline Script):-
$env:ENV="FOO"
Output:-
2021-09-03T13:49:28.9213455Z
2021-09-03T13:49:28.9214265Z c:\Agent\_work\r1\a>$env:ENV="FOO"
**2021-09-03T13:49:28.9219788Z The filename, directory name, or volume label syntax is incorrect.**
2021-09-03T13:49:28.9298991Z ##[error]Script failed with error: Error: The process 'c:\Agent\_work\_temp\azureclitaskscript1630676963575.bat' failed with exit code 1
The same command works perfectly fine in local VM PowerShell but not sure why it doesn't from Pipeline. Any suggestions?
Note: Directory path is correct ONLY.
答案1
得分: 2
脚本似乎是以.bat
格式编写的,而$env:ENV=...
不是受支持的bat
命令。
英文:
The script seems to be in .bat
and $env:ENV=...
is not a supported bat
command.
答案2
得分: 1
>$env:ENV="FOO"
这是一个PowerShell脚本。
您需要在Azure CLI任务中指定使用PowerShell来运行脚本。
在Azure CLI任务V1中,似乎没有选项可以实现这一点。
我建议您可以使用Azure CLI任务的版本2:
- task: AzureCLI@2
displayName: 'Azure CLI '
inputs:
azureSubscription: xxx
scriptType: ps
scriptLocation: inlineScript
inlineScript: '$env:ENV="FOO"'
英文:
>$env:ENV="FOO"
This script is PowerShell Script.
You need to specify the use of PowerShell in the Azure CLI task to run the script.
In Azure CLI task V1 , it seems that there is no option to achieve this.
I suggest that you can use the Azure CLI task version 2:
- task: AzureCLI@2
displayName: 'Azure CLI '
inputs:
azureSubscription: xxx
scriptType: ps
scriptLocation: inlineScript
inlineScript: '$env:ENV="FOO"'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论