0

Here is my .gitlab-ci.yml file, inspired by @GrandFleet's answer:

image: node:latest
  
cache:
  paths:
  - node_modules/

stages:
  - test

test_async:
  stage: test
  services:
   - trufflesuite/ganache-cli
  script:
   - npm install truffle
   - ./node_modules/truffle/build/cli.bundled.js compile
   - ./node_modules/truffle/build/cli.bundled.js migrate --network gitlab
   - ./node_modules/truffle/build/cli.bundled.js test --network gitlab

When I run this on Gitlab, I get this error on ./node_modules/truffle/build/cli.bundled.js migrate --network gitlab:

$ ./node_modules/truffle/build/cli.bundled.js migrate --network gitlab
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Unknown network "gitlab". See your Truffle configuration file for available networks.
Truffle v5.4.25 (core: 5.4.25)
Node v17.2.0
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

Should I set up a Gitlab network in my truffle-config.js? And if so, how?

EDIT:

Here is my truffle-config.js file:

module.exports = {
  networks: {
    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 7545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.10",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: false,
         runs: 200
       },
      }
    }
  }
};
7
  • Yes, you could try adding a gitlab network, or using the development network instead.
    – Ismael
    Commented Dec 18, 2021 at 22:52
  • @Ismael And how exactly do I do that? That was my real question Commented Dec 20, 2021 at 15:52
  • What does your truffle-config.js look like?
    – Ismael
    Commented Dec 26, 2021 at 17:15
  • I edited my question with the truffle-config.js file Commented Jan 1, 2022 at 14:07
  • 1
    Of course, I didn't set up a network for testing! So I did define a 'ropsten' network in truffle-config and did --network ropsten, and it's all good! Commented Jan 2, 2022 at 19:36

1 Answer 1

0

To run tests on Gitlab CI, we need to use a test network such like Ropsten, Kovan or Rinkeby. In the truffle-config.js, in networks, add (if using Ropsten, in this case):

ropsten: {
      provider: () => {
        return new HDWalletProvider(mnemonic, rpc_url);
      },
      network_id: '3',
    }

and the .gitlab-ci.yml file should look like:

image: node:latest
  
cache:
  paths:
  - node_modules/

stages:
  - test

test_async:
  stage: test
  services:
   - trufflesuite/ganache-cli
  script:
   - echo "MNEMONIC"=$MNEMONIC >> ".env"
   - export NODE_OPTIONS=--openssl-legacy-provider
   - npm install truffle
   - ./node_modules/truffle/build/cli.bundled.js compile
   - ./node_modules/truffle/build/cli.bundled.js migrate --network ropsten
   - ./node_modules/truffle/build/cli.bundled.js test --network ropsten

Where --network ropsten refers to the "ropsten" network defined in truffle-config.js.

I have written a more detailed solution in this tutorial: https://blog.benjaminazoulay.com/how-to-run-truffle-tests-in-gitlab-ci

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.