azure - 将 Golang 环境变量注入(inject) Azure Pipeline

标签 azure go pipeline cicd

我目前正在将一些构建组件迁移到Azure Pipelines,并尝试为所有 Golang 相关进程设置一些环境变量。我希望在管道中执行以下命令:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build [...]

当利用提供的Golang集成时,很容易为Go相关进程添加参数,但为所有(或每个人)设置一个环境变量>Go 过程似乎不可能。 GoTool 都没有 或默认的 Go 任务似乎支持它,并执行 script 似乎也不支持包含 shell 执行的任务。

我还尝试向整个管道进程添加一个环境变量来定义所需的标志,但这些似乎被 Azure Pipelines 本身提供的 Go 任务忽略。

是否有一种方法可以将这些标志添加到每个(或单个)go 进程中,例如我如何在以下代码块中执行此操作(其中创建了 flags 输入行由我来完成)?

- task: Go@0
  inputs:
    flags: 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64'
    command: 'build'
    arguments: '[...]'
    workingDirectory: '$(System.DefaultWorkingDirectory)'
  displayName: 'Build the application'

最佳答案

根据我找到的信息和长时间的调试,我最终使用了一种解决方法,在 CmdLine@2 中运行 golang 命令任务,而不是。由于 GoTool@0 如何设置管道和环境,这是可能的。

因此,下面的代码片段满足了我的目的。

steps: 
- task: GoTool@0
  inputs:
    version: '1.19.0'
- task: CmdLine@2
  inputs:
    script: 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

关于azure - 将 Golang 环境变量注入(inject) Azure Pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75171491/

相关文章:

azure - Windows 手机 8.1 : Send notification to specified user

pointers - 在 golang 中返回一个指针

azure - AKS 日志格式已更改

c# - Azure 表存储 - 通过分区键删除实体 REST API

javascript - 为具有需要编译的静态 Assets 的项目推荐的 Go 项目结构和构建系统?

go - 保存 Hook 上的 Emacs Golang gofmt - 不格式化

ruby - 即使满足先决条件,如何强制执行 Rake 中的任务?

f# - 管道中的 printfn

python - sklearn 管道适合 : AttributeError: lower not found

Azure 辅助角色扩展