Blog

Chip Off The Ol’ Blockchain – Part 3: How to Setup a CI/CD Pipeline with VSTS and Truffle

Visual Studio Team Services (VSTS) has quickly become one for enterprise and indie developers the tool of choice for managing code repositories, processes, and test, and builds. With the rise of Solidity as the language of choice, Inevitably the need for CI/CD pipelines for Solidity smart contracts will grow. This short tutorial outlines how to use VSTS to create a simple pipeline for Solidity and Truffle.

  1. With your code checked in, click +New to add a new build definition to VSTS.

    New Build Definition

  2. Select your source. You’ll want to also select the repository and branch you want to build from too, then click Continue.

    Select Source

  3. On the next step, click on Empty process.

    Empty Process

  4. Name the build something descriptive and select Hosted Linux Preview for the Agent Queue.

    Name and Agent

  5. Next, click the + button next to Phase 1 to add a task. Search for npm, then select Add next to npm from the search results.

    Add NPM

  6. Search for shell script and click Add next to shell script in the search results.

    Add Shell Script

  7. Click on the npm task to edit it. This task will install Truffle on the Linux agent and also install ganache-cli to use as the test network. Set the Display name to install ganache-cli and truffle. For Command, select custom. Paste in install -g truffle ganache-cli into Command and arguments.

    Edit NPM

  8. Click on the Shell Script task. This task will actually run your Solidity unit tests. Set the Version to 3.* , Display name to run tests, and Type to inline. Paste in the following code into the Script field.
     #!/bin/bash
    
     # Starts the Ganache blockchain in the background.
     ganache-cli > /dev/null &
    
     # Deploys the contracts to the Ganache network
     truffle deploy --reset --network test
    
     # Tuns the tests for the contracts
     truffle test --network test
    
     # Kills the Ganache blockchain running in the background.
     kill -KILL $(jobs -p)
    
     exit 0
    

    Note: the network test is defined in the truffle.jsfile in the root of the truffle project that is checked in. Edit the truffle.json file and add the test network if you don’t already have a ganache-cli network defined in the truffle.js file. It needs to have the host set to 127.0.0.1, the port to 8545, and network_id to *.

     module.exports = {
       networks: {
         test: {
           host: "127.0.0.1",
           port: 8545,
           network_id: "*" // Match any network id
         }   
       }
     };
    

    Edit Shell Script

  9. From the Save & queue menu, select Save, and name the build definition.

    Save Build

That’s it. You can now test it by queuing a new build and watching the output. Also, you can add any additional tasks related to your CI/CD pipeline or turn on Enable Continuous Integration under the Triggers tab so that the build definition fires when new code is checked into the repository.

Blaize Stewart

Recent Posts

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

5 days ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

3 weeks ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

1 month ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

1 month ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago

Mastering Compliance: The Definitive Guide to Managed Compliance Services

In the intricate landscape of modern business, compliance is both a cornerstone of operational integrity…

2 months ago