Azure-pipelines-tasks: Installing additional go tools

Created on 9 Aug 2018  路  12Comments  路  Source: microsoft/azure-pipelines-tasks

Troubleshooting

This is not a bug report - I'm more interested in how I could solve my problem.

Environment

  • Server: VSTS

  • Agent: Hosted

Issue Description

I'm trying to build a repository containing golang code. Now that would not be the problem on VSTS but I have to restore dependencies using dep. This demands the following steps:

  1. Fetch the dep tool:
go get -u github.com/golang/dep/cmd/dep

This should compile the dep tool and place it in $GOPATH/bin.

  1. The I'd have to use this tool to restore dependencies:
dep ensure
  1. The we can build the program:
go build main.go -o main

Now, step one and three are not a problem and they are covered by the prerelease go tasks. But how could I install the dep tool?

Release enhancement

Most helpful comment

@imalokagrawal Of course I can do anything using a ps-script, but considering that dep is intended to be the go projects reference dependency management tool and soon every codebase out there will make use of it I think the possibility to install and run this tool out of the box should be something to be thought about!

All 12 comments

Hi @enzian - I've used the Bash/Shell++ tasks with an inline script for some similar situations. I was using gocover-cobertura to convert the code coverage of my Go code to cobertura format so that VSTS could understand the coverage results.

I used the Go preview task to do a go get -u github.com/t-yuki/gocover-cobertura similar to your step 1 above, and then a shell step to use the tool. You should be able to run your step 2 dep ensure via an inline Bash/shell Task as well.

The Bash/shell Task is relatively new and ships with VSTS: https://docs.microsoft.com/en-us/vsts/pipelines/tasks/utility/shell-script?view=vsts

Shell++ is available via this extension: https://marketplace.visualstudio.com/items?itemName=ms-devlabs.utilitytasks

@enzian @calebcartwright you are right, this feature is not available today in the task.
Adding @imalokagrawal. do you think this can be an enhancement?

@enzian: as pointed out by @calebcartwright, use any command line task like bash/shell to achieve this.

@imalokagrawal Of course I can do anything using a ps-script, but considering that dep is intended to be the go projects reference dependency management tool and soon every codebase out there will make use of it I think the possibility to install and run this tool out of the box should be something to be thought about!

I see the benefit of dep being an available option (as a standalone task type) so I'd be +1 on that. However, I think it would be worth considering the changes that came with Go 1.11, including modules, current and planned vgo/go get enhancements, etc., before making dep the default/standard for all projects on the VSTS side.

@calebcartwright I absolutely agree that making it run by default would be a very bad move!! A tool install task would be my way to go too!

Just as a quick check-in. Here is how I solved this issue:

  1. Have the go tool installer task run first. Important here is, to specify where you want your GOBIN and GOPATH to be since we'll need this values later!

  2. Run the following PS script:

echo "Installing Dep ..."
go get -u github.com/golang/dep/cmd/dep
echo "Adding GOBIN to path: $env:GOBIN"
$env:PATH += ":$env:GOBIN"
echo "Added $env:GOBIN to path $env:PATH"

echo "Moving source files"

Copy-Item $env:ProjectRoot -Filter *.* -Destination $env:GOPATH/src/demo.organization.com -Recurse
$env:ProjectRoot = "$env:GOPATH/src/demo.organization.com"

echo "moving to $env:ProjectRoot"
cd $env:ProjectRoot
echo "Restoring dependencies..."
dep ensure

get-childitem $env:ProjectRoot 

echo "Building ..."
go build -o "main" ./main.go

get-childitem $env:ProjectRoot 
  1. Have a Copy Files Task move your files from $(GOPATH)/src/demo.organization.com to the stageing directory and upload them...

Adding @pulkitaggarwl

This should also be helpful, at least for those defining their pipeline in yaml
https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/go?view=vsts#set-up-a-go-workspace

Thanks folks for the feedback. Please keep them coming. This has been registered as a request in the backlog. Also, one other forum where you can add this feedback is our User Voice. Similar feedback from the community will help us prioritize this.
Regards, Pulkit

This issue is stale because it has been open for a year with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

Hi guys,

I am also blocked by go get -u

I want to use go get -u to install some cli for end to end testing of my project,
I forked the project and adding an azp which make sure the project itself is good.
but when I use go get -u

go get -u github.com/square/certstrap && certstrap -h ========================== Starting Command Output =========================== /bin/bash --noprofile --norc /home/vsts/work/_temp/63c536d3-b451-4474-b6dc-1eb3a079675a.sh # github.com/square/certstrap/cmd ../../../go/src/github.com/square/certstrap/cmd/init.go:38:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:42:15: cannot use cli.IntFlag literal (type cli.IntFlag) as type cli.Flag in slice literal: cli.IntFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:47:15: cannot use cli.IntFlag literal (type cli.IntFlag) as type cli.Flag in slice literal: cli.IntFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:51:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:56:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:60:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:64:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:68:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:72:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:76:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal: cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver) ../../../go/src/github.com/square/certstrap/cmd/init.go:76:18: too many errors ##[error]Bash exited with code '2'.

Hope go get -u issue can be fixed.

Was this page helpful?
0 / 5 - 0 ratings