CI sample setup with GO - 24i/fokuson-developer-portal GitHub Wiki
Setup an environment for continuous integration and have your widgets build and tested on a per push, by cron or on demand basis. Create pipelines for snapshots, milestones, release candidates or releases.
Dedicated server with Internet access and docker engine installed
-
Create gocd home directory on server
mkdir GOCD; cd GOCD; mkdir go godata; chmod 777 ../GOCD go godata -
Start GO server
docker run -d -p8153:8153 gocd/gocd-server:v20.5.0Point browser to: http://<your_server>:8153/go
-
Start GO agent
GO_SERVER_URL=http://<your_server>:8153/go gocd/gocd-agent-ubuntu-16.04:v20.5.0NB! is where the GOCD directory was created in step 1 and “<your_server>” refers to the docker server, not container.
Repeat the following steps for both server and agent container:

#!
# docker exec -it -u 0 <container ID> /bin/bash
- Change to user “go”
#!
# su - go
- Create key and add to the ssh agent
#!
$ ssh-keygen
#!
eval `ssh-agent`
#!
ssh-add ~/.ssh/id_rsa
If you renamed the key, replace id_rsa with the key file name.
-
From Bitbucket, choose Personal settings from your avatar in the lower left. The Account settings page opens.
-
Click SSH keys. If you've already added keys, you'll see them on this page.
-
In your terminal window, copy all of the contents of your public key file. If you renamed the key, replace id_rsa.pub with the public key file name.
$ cat ~/.ssh/id_rsa.pub
-
Select and copy the key output in the clipboard. If you have problems with copy and paste, you can open the file directly with Notepad. Select the contents of the file (just avoid selecting the end-of-file characters).
-
From Bitbucket, click Add key.
-
Enter a Label for your new key. e.g.: docker_gocd_agent, docker_gocd_server These labels are only for you for referencing, and you can name them however you choose.
-
Paste the copied public key into the SSH Key field. You may see an email address on the last line when you paste. It doesn't matter whether or not you include the email address in the Key.
-
Click Save. After you add a key, you can edit the key's Label but not the key itself. To change the key's contents, you need to delete and re-add the key.
-
Return to the terminal window and verify your configuration and username by entering the following command:
#!
$ ssh -T [email protected]
You should see something similar to a successful connection. The resulting message tells you which of your Bitbucket accounts can log in with that key.
#!
$ ssh -T [email protected]
The authenticity of host 'bitbucket.org (18.205.93.0)' can't be established.
RSA key fingerprint is SHA256:azXQOXSRBEiUtuE1AikJYKwbHaxvSc0ojez4YXaGp1A.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org,18.205.93.0' (RSA) to the list of known hosts.
logged in as aronM
You can use git or hg to connect to Bitbucket. Shell access is disabled
If you get an error message with
#!
Permission denied (publickey)
, check the [Troubleshoot SSH issues](Troubleshoot SSH issues) page for help.

After you've got a SSH key set up, use the SSH URL the next time you clone a repository. If you already have a repository that you cloned over HTTPS, change the remote URL for your repository to use its SSH URL.
Ensure SSH has been setup for both containers before continuing.
The next step is to configure the GOCD agent, so the one listed with the image name “gocd/gocd-agent” when listing Docker images with docker ps
#!
# docker exec -it -u 0 <container ID> /bin/bash
First, update the local repository to ensure you install the latest versions of Node.js and npm. Execute the following command:
#!
# apt-get -y update
#!
# apt-get -y upgrade
Next, add the NodeSource repository to the system with:
#!
# curl -sL https://deb.nodesource.com/setup_12.x | bash -
(or change URL to latest stable as of https://nodesource.com/)
The output will prompt you to use the following command if you want to install Node.js and npm:
#!
# apt-get install -y nodejs gcc g++ make
Verify the installed software with the commands:
#!
# node --version
# npm --version
You should have an output similar to this:
#!
root@7da19e4a4cdd:/# node --version
v12.18.2
root@7da19e4a4cdd:/# npm --version
6.14.5
-
Point your browser to:
http://<your_server>:8153/go
-
Enable the agent (Agents > Static > Enable)

-
Add Environment “build_widgets”

-
Add the agent to the environment

Edit the Config XML
Insert snippet between and tags. Replace “acme” with your name.
The Git URL ([email protected]:nordija/widgets-acme.git) needs to be correct.
Also, the branch="bugfix_3_27" needs to be the right branch of the repository
#!
<pipelines group="Acme">
<pipeline name="acme_widgets_bugfix_3_27">
<materials>
<git url="[email protected]:nordija/widgets-acme.git" branch="bugfix_3_27" dest="work" materialName="acme_widgets" />
</materials>
<stage name="build_package" cleanWorkingDir="true">
<jobs>
<job name="build_widgets">
<tasks>
<exec command="npm" workingdir="work">
<arg>install</arg>
<runif status="passed" />
</exec>
<exec command="npm" workingdir="work">
<arg>run</arg>
<arg>build</arg>
<runif status="passed" />
</exec>
</tasks>
<artifacts>
<artifact type="build" src="work/dist/*.zip" dest="pkg" />
<artifact type="build" src="work/dist/zips/**/*.zip" dest="pkg" />
</artifacts>
</job>
</jobs>
</stage>
</pipeline>
</pipelines>
GOCD Config XML snippet



GOCD Documentation https://docs.gocd.org/current/
SSH Keys https://bitbucket.org/account/settings/ssh-keys/
GOCD server https://hub.docker.com/r/gocd/gocd-server
GOCD Agent https://hub.docker.com/r/gocd/gocd-agent-ubuntu-16.04