# Building an Automated Test Pipeline for Continuous Delivery with GoCD

- Canonical: https://33rdsquare.com/building-an-automated-test-pipeline-for-continuous-delivery-with-gocd/
- Published: 2024-03-06
- Author: Brian Lucas
- Categories: [App & Browser Testing Automation](https://33rdsquare.com/category/browser/browser-testing/)

---

As someone who has spent over a decade in test automation across various organizations, I have seen first-hand the transformational impact continuous testing can create. **Companies that embed automation into their software pipeline are able to achieve up to 30% faster release cycles and 50% reduction in production defects** as per recent reports.

However, setting up an assembly line for continuous testing remains aDevOps challenge at most enterprises. The process spans multiple stages – builds, tests, security checks, deployments etc. Add the matrix of environments, browsers and devices to validate against. **Without the right CI/CD framework, managing this automation complexity becomes a bottleneck that breaks velocity.**

This is where GoCD, the continuous delivery server I have come to rely on for modeling exceptionally smooth workflow orchestration. Backed by ThoughtWorks, it offers unparalled capabilities for value stream mapping. In this comprehensive guide, let me walk you through how easy GoCD makes building automated pipelines – **integrating tools, running parallel tasks, gathering metadata and beyond!**

## Understanding GoCD‘s Capabilities

Before we jump into building a pipeline, its useful to understand what makes GoCD so powerful:

**Visual Pipeline Modeling** – The value stream map makes dependencies extremely intuitive. Easily model complex workflows running across teams, environments and tools.

**Infrastructure Independent** – With its agent architecture, pipelines remain consistent irrespective of underlying infrastructure. Agents can scale on-demand.

**Standardization Using Templates** – Template pipelines allow reuse of test logic across teams. Also define organization‘s best practices.

**Extensive Tool Support** – Out of the box support for ~50 tools. Clean plugin model to integrate virtually any new testing tool needed.

**End-to-End Visibility** – Single pain of glass across build status, deployments, test reports etc. Compare builds and trace artifacts.

Talking about artifacts…

### How Pipelines Accelerate Release Cycles

Modern software delivery relies on practices like:

- **Continuous Integration** – Developers merge code changes multiple times daily, which is validated by automated builds and tests. Fast feedback accelerates development.
- **Infrastructure as Code** – Immutable infrastructure definitions help standardize deployment environments across dev, test, staging etc.
- **Shift Left Testing** – Start testing early against commits in parallel paths to break feedback cycle.

This is where GoCD pipelines comes together to achieve **accelerated cycle times while maintaining quality**. Let‘s see how!

## Modeling Pipelines for Parallel Execution

As an example pipeline, we will use a customer portal application that allows users to view their profiles and accounts.

Some functional flows we want to test:

- Login flows – invalid password, locked accounts etc.
- Navigation across profile, accounts, settings pages
- Verifying transactions and statements
- Security – access controls across user types

The sequential flow would execute:

1. Install dependencies
2. Run API test suites
3. Run integration tests
4. Run functional UI tests
5. Security analysis
6. Deploy on test environment

With **sequential runs, this workflow can take hours across committed changes**. Now see how GoCD helps parallelize:

![Pipeline flow](https://raw.githubusercontent.com/gocd/www.go.cd/master/source/assets/images/features/value_stream_map.png)

The above delivery pipeline is modeled in GoCD‘s value stream map. It offers a **highly intuitive way to visualize dependencies between tasks** using nodes and edges.

Some ways we are **accelerating cycle times**:

- Run API, integration and UI tests in parallel to reduce test time
- Break UI tests across browser types to further divide test suites
- Set agent requirements to allocate appropriate infrastructure
- Model deployment lifecycles across multiple environments

Next let‘s look at how to model this in GoCD.

## Creating Your First Pipeline

I will walk you through creating a simple pipeline for building and testing code changes. We will take the example of a web application and add stages for:

- Build
- Unit Testing
- Integration Testing
- UI Functional Testing
- Security Testing
- Deploy to Staging

Make sure GoCD server and agent are installed first. The agents can be deployed on multiple machines.

**1. Define Pipeline Basics**

- Give pipeline a name eg. MyApp-Pipeline
- Specify source code repository under Materials
- Set target branch to build – master, feature etc

**2. Add Build Stage**

- Name stage as "Build"
- Under Jobs, add a job named "Build"
- Add tasks to compile code, run linting checks etc

```
npm install
npm run build
```

**3. Add Testing Stages and Jobs**

Similarly add stages for different testing flows:

- **Unit Tests** – Runs isolated unit tests. Can configure code coverage checks.
- **API Tests** – Validates backend REST APIs. Example tools – Postman, Cucumber etc
- **UI Flows** – End-to-end functional validation across UI. Example runners – Selenium, Cypress.

Let me share a pro-tip on **allocating test suites to GoCD agents** for parallelism:

- Categorize tests by functionality – login, payments, admin flows
- Break large suites into smaller batches of tests
- Map batches to run across multiple agents

This helps accelerate pipeline execution!

## Configuring Cross Browser Testing with BrowserStack

For testing web UI functionality across browsers, devices and resolutions, I generally integrate **BrowserStack**. This cloud based automation platform provides instant access to 2000+ test environments without needing physical devices.

Some advantages of BrowserStack integration:

✅ Run Selenium and Appium based tests
 ✅ Supports all languages and frameworks
 ✅ Debug tests interactively
 ✅ Detailed custom reports

**Here is how I integrate it with GoCD pipelines:**

1. Sign up on BrowserStack and get access credentials
2. Add credentials as environment variables in GoCD
3. Configure test jobs with remote Selenium hub URL
4. Specify browser, device and OS capabilities

And that‘s it! Our UI test suites now run across Chrome, Firefox, Safari and IE without any additional infrastructure.

For mobile app testing, BrowserStack further offers access to **real iOS and Android devices**. This helps test latest OS versions without needing to procure devices physically.

## Gathering Feedback into the GoCD Dashboard

A key aspect I love about GoCD is the end-to-end traceability it provides. Out of the box, the dashboard shows live status of pipeline runs including:

✅ Build and test results
 ✅ Deployment status across environments
 ✅ User acceptance testing progress

Additionally for custom tools, we can push metadata using GoCD APIs:

- Test coverage reports after unit testing runs
- Performance benchmark results
- Security scan summaries from tools like OWASP ZAP
- Code quality analysis from Sonarqube

**This provides a single pane of glass across the entire pipeline**. Developers get full context without switching systems while triggering releases.

## Conclusion: Accelerate Without Compromising Quality

In my decade long experience in test automation, I find GoCD striking the perfect balance between accelerating release cycles through CI/CD while assuring quality. The fact that powerhouses like Intel, Adobe, Amdocs run GoCD for their mission critical pipelines says it all!

With its clean abstractions, modeling of complex workflows across teams is stupidly simple. When you combine cloud based test platforms like BrowserStack, the possibilities for scaling test automation are endless. Ultimately, GoCD answers the enterprise need for continuous testing and visibility most efficiently.

What has your experience been with GoCD or other CI/CD tools? What integrations worked best for your needs? Would love your thoughts!

---

Source: [Building an Automated Test Pipeline for Continuous Delivery with GoCD](https://33rdsquare.com/building-an-automated-test-pipeline-for-continuous-delivery-with-gocd/)
