环境变量未被识别。

huangapple go评论149阅读模式
英文:

Env variable not being recognized

问题

CICD: Azure DevOps
任务:Azure CLI
脚本位置:内联脚本
任务版本:1
代理:自托管
语言:Go

当我从Azure Pipeline传递环境变量时,我遇到了一个奇怪的问题。

命令(内联脚本):

  1. $env:ENV="FOO"

输出:

  1. 2021-09-03T13:49:28.9213455Z
  2. 2021-09-03T13:49:28.9214265Z c:\Agent\_work\r1\a>$env:ENV="FOO"
  3. **2021-09-03T13:49:28.9219788Z 文件名、目录名或卷标语法不正确。**
  4. 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):-

  1. $env:ENV="FOO"

Output:-

  1. 2021-09-03T13:49:28.9213455Z
  2. 2021-09-03T13:49:28.9214265Z c:\Agent\_work\r1\a>$env:ENV="FOO"
  3. **2021-09-03T13:49:28.9219788Z The filename, directory name, or volume label syntax is incorrect.**
  4. 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:

  1. - task: AzureCLI@2
  2. displayName: 'Azure CLI '
  3. inputs:
  4. azureSubscription: xxx
  5. scriptType: ps
  6. scriptLocation: inlineScript
  7. inlineScript: '$env:ENV="FOO"'

环境变量未被识别。

huangapple
  • 本文由 发表于 2021年9月3日 21:58:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/69046125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定