Azure DevOps Go流水线运行失败,求可用YAML配置方案
可正常运行的Azure DevOps Go流水线YAML配置
你遇到的错误源于Go Modules模式下的命令适配问题:旧版go get -d命令在模块项目中执行逻辑已变更,且你使用的Go 1.13.5版本较老,存在兼容性问题。以下是适配Go Modules项目的可用流水线配置:
trigger: - main pool: vmImage: 'ubuntu-latest' steps: # 安装指定版本的Go(推荐使用较新版本,这里以1.21.6为例) - task: GoTool@0 inputs: version: '1.21.6' goPath: '$(Agent.ToolsDirectory)/Go' # 若项目未初始化Go模块,自动执行初始化(按需保留) - task: Go@0 inputs: command: 'custom' customCommand: 'mod init github.com/你的用户名/你的仓库名' workingDirectory: '$(System.DefaultWorkingDirectory)' condition: ne(exists('$(System.DefaultWorkingDirectory)/go.mod'), 'true') # 下载项目依赖 - task: Go@0 inputs: command: 'mod' arguments: 'download' workingDirectory: '$(System.DefaultWorkingDirectory)' # 构建Go应用,直接输出到产物 staging 目录 - task: Go@0 inputs: command: 'build' arguments: '-o $(Build.ArtifactStagingDirectory)/你的应用名称' workingDirectory: '$(System.DefaultWorkingDirectory)' # 发布构建产物到Azure DevOps - task: PublishBuildArtifacts@1 inputs: artifactName: 'drop' pathtoPublish: '$(Build.ArtifactStagingDirectory)'
注意事项
- 替换配置中的
github.com/你的用户名/你的仓库名为你的实际Go模块路径 - 将
你的应用名称替换为你期望生成的可执行文件名称 - 若项目已存在
go.mod文件,可删除mod init对应的步骤 - 选择较新的Go版本(如1.20+)能更好兼容Azure DevOps的Go任务
内容的提问来源于stack exchange,提问作者Dean Schulze
相关产品推荐
相关产品推荐

