Matrix configuration with Jenkins pipelines

后端 未结 5 1963
青春惊慌失措
青春惊慌失措 2020-12-24 12:12

The Jenkins Pipeline plugin (aka Workflow) can be extended with other Multibranch plugins to build branches and pull requests automatically.

What would

5条回答
  •  难免孤独
    2020-12-24 12:52

    In order to test each commit on several platforms, I've used this base Jenkinsfile skeleton:

    def test_platform(label, with_stages = false)
    {
        node(label)
        {
            // Checkout
            if (with_stages) stage label + ' Checkout'
            ...
    
            // Build
            if (with_stages) stage label + ' Build'
            ...
    
            // Tests
            if (with_stages) stage label + ' Tests'
            ...
        }
    }
    
    /*
    parallel ( failFast: false,
        Windows: { test_platform("Windows") },
        Linux:   { test_platform("Linux")   },
        Mac:     { test_platform("Mac")     },
    )
    */
    
    test_platform("Windows", true)
    test_platform("Mac",     true)
    test_platform("Linux",   true)
    

    With this it's relatively easy to switch from a sequential to a parallel execution, each of them having their pros and cons:

    • Parallel execution runs much faster, but it doesn't contain the stages labelling
    • Sequential execution is much slower, but you get a detailed report thanks to stages, labelled as "Windows Checkout", "Windows Build", "Windows Tests", "Mac Checkout", etc.)

    I'm using the sequential execution for the time being, until I find a better solution.

提交回复
热议问题