Go (Language – Golang) with GoCD – Part Two

1. A standalone app with unversioned external/third parties library

In this example, the app required external libraries.  In this example, my app use “stringutil” from golang example.  When I said “unversioned”, I mean my app does not care which version ( version from a year ago or latest ) of stringutil GoCD will use to build my app, it will use “go get” to pull the latest version as of the build run.

Create a new pipeline in GoCD called “App_with_Unversioned_Libraries”

Screen Shot 2016-10-07 at 8.09.10 PM.png

Screen Shot 2016-10-07 at 8.27.40 PM.png

Similar to the “Standalone” app from my previous post,  check out the repos to src/github.com/barrowkwan/gocd_golang_hello_ext.  If Go agent’s root folder is /var/lib/go-agent/pipelines, you will find the repos checkout at /var/lib/go-agent/pipelines/App_with_Unversioned_Libraries/src/github.com/barrowkwan/gocd_golang_hello_ext.

** You cannot specify “Destination Directory” in the “Add Pipeline” screen, you will need to save the pipeline and use “Edit Material” to update “Destination Directory”.

Screen Shot 2016-10-07 at 8.29.08 PM.png

Create a stage and a job in that stage, then create job that run the build script ( src/github.com/barrowkwan/gocd_golang_hello_ext/build.sh )

Screen Shot 2016-10-07 at 8.29.44 PM.png

When Go run this build script, it will use Go Agent’s root folder  ( ie /var/lib/go-agent/pipelines/App_with_Unversioned_Libraries ) as the working directory.  Since our repos has checkout under /var/lib/go-agent/pipelines/App_with_Unversioned_Libraries as src/github.com/barrowkwan/gocd_golang_hello_ext, if we configure GOPATH to /var/lib/go-agent/pipelines/App_with_Unversioned_Libraries, “go” will be able to look up our app or any other external libraries in the src folder.

Screen Shot 2016-10-07 at 8.36.25 PM.png

In my build.sh script, I use ‘pwd’ to set up environment variable GOPATH.  Unless you configure your job in GoCD to run your script from a different working directory; otherwise, the script will run from Go agent’s root folder ( ie /var/lib/go-agent/pipelines/App_with_Unversioned_Libraries ).  Since this app needs stringutil, when the build script called “go get”, it will download latest version of stringutil from github to src folder ( ie /var/lib/go-agent/pipelines/App_with_Unversioned_Libraries/src/github.com/golang/example/stringutil )

When build.sh run “go build”, it will build my app with the version checkout by GoCD under src/github.com/barrowkwan/gocd_golang_hello_ext and an “unversioned” stringutil under src/github.com/golang/example/stringutil.

This entry was posted in GoCD, Golang. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s