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”
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”.
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 )
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.
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.