README.md in knapsack_pro-0.28.1 vs README.md in knapsack_pro-0.29.0

- old
+ new

@@ -92,10 +92,11 @@ - [Info for CircleCI users](#info-for-circleci-users) - [Info for Travis users](#info-for-travis-users) - [Info for semaphoreapp.com users](#info-for-semaphoreappcom-users) - [Info for buildkite.com users](#info-for-buildkitecom-users) - [Info for snap-ci.com users](#info-for-snap-cicom-users) + - [Info for Jenkins users](#info-for-jenkins-users) - [FAQ](#faq) - [How to run tests for particular CI node in your development environment](#how-to-run-tests-for-particular-ci-node-in-your-development-environment) - [for knapack_pro regular mode](#for-knapack_pro-regular-mode) - [for knapsack_pro queue mode](#for-knapsack_pro-queue-mode) - [What happens when Knapsack Pro API is not available/not reachable temporarily?](#what-happens-when-knapsack-pro-api-is-not-availablenot-reachable-temporarily) @@ -677,10 +678,73 @@ # Step for Spinach bundle exec rake knapsack_pro:spinach Please remember to set up token like `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` as global environment. +#### Info for Jenkins users + +In order to run parallel jobs with Jenkins you should use Jenkins Pipeline. +You can learn basics about it in the article [Parallelism and Distributed Builds with Jenkins](https://www.cloudbees.com/blog/parallelism-and-distributed-builds-jenkins). + +Here is example `Jenkinsfile` working with Jenkins Pipeline. + +``` +timeout(time: 60, unit: 'MINUTES') { + node() { + stage('Checkout') { + checkout([/* checkout code from git */]) + + // determine git commit hash because we need to pass it to knapsack_pro + COMMIT_HASH = sh(returnStdout: true, script: 'git rev-parse HEAD').trim() + + stash 'source' + } + } + + def num_nodes = 4; // define your total number of CI nodes (how many parallel jobs will be executed) + def nodes = [:] + + for (int i = 0; i < num_nodes; i++) { + def index = i; + nodes["ci_node_${i}"] = { + node() { + stage('Setup') { + unstash 'source' + // other setup steps + } + + def knapsack_options = """\ + KNAPSACK_PRO_CI_NODE_TOTAL=${num_nodes}\ + KNAPSACK_PRO_CI_NODE_INDEX=${index}\ + KNAPSACK_PRO_COMMIT_HASH=${COMMIT_HASH}\ + KNAPSACK_PRO_BRANCH=${env.BRANCH_NAME}\ + """ + + // example how to run cucumber tests in Knapsack Pro Regular Mode + stage('Run cucumber') { + sh """${knapsack_options} bundle exec rake knapsack_pro:cucumber""" + } + + // example how to run rspec tests in Knapsack Pro Queue Mode + // Queue Mode should be as a last stage so it can autobalance build if tests in regular mode were not perfectly distributed + stage('Run rspec') { + sh """KNAPSACK_PRO_CI_NODE_BUILD_ID=${env.BUILD_TAG} ${knapsack_options} bundle exec rake knapsack_pro:queue:rspec""" + } + } + } + } + + parallel nodes // run CI nodes in parallel +} +``` + +Remember to set environment variables in Jenkins configuration with your API tokens like `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` and `KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER`. +Here is [list of environment variables per test runner](#set-api-key-token). + +Above example shows how to run cucumber tests in regular mode and later the rspec tests in queue mode to autobalance build. +If you are going to relay on rspec to autobalance build when cucumber tests were not perfectly distributed you should be aware about [possible edge case if your rspec test suite is very short](#why-my-tests-are-executed-twice-in-queue-mode-why-ci-node-runs-whole-test-suite-again). + ## FAQ ### How to run tests for particular CI node in your development environment #### for knapack_pro regular mode @@ -938,11 +1002,11 @@ Thanks to that when for some reason the tests executed for cucumber in regular mode will not be well balanced across CI nodes (for instance when one of CI node has bad performance) then the rspec tests executed later in the queue mode will autobalance your build. ### Why my tests are executed twice in queue mode? Why CI node runs whole test suite again? -This may happen when one of your CI node started work when all other CI nodes already executed whole test suite. -This slow CI node will initialize a new queue hence the tests executed twice. To solve this problem you should set `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`. +This may happen when one of your CI node started work later when all other CI nodes already executed whole test suite. +The slow CI node will initialize a new queue hence the tests executed twice. To solve this problem you should set `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`. Please [read this](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node). ## Gem tests ### Spec