0

I have a project which features tests which only run on Linux and other tests which only run on Windows.

I have a Linux agent and a Windows agent. I need to check out the project (and its multiple dependencies) on both agents before I can run the tests on their respective agents.

What's the best method of doing this without repeating code?

I've managed to get a matrix block working like so:

 stage('SCM Checkout Matrix')
        {
            matrix {
                axes {
                    axes {
                        name 'AGENT'
                        values 'builtin', 'jenkins-uk-win7'
                    }
                }

                stages {
                    stage("SCM Checkout") {
                        options {
                            lock( 'synchronous-matrix' )
                        } 
                        agent {label "${AGENT}"}
                        steps {
                            <many git checkouts in here>
                           
                        }                        
                    }
                
                }
            }

But this seems hideously complicated and also makes the dashboard horribly messy: enter image description here

I've also tried defining multiple agent labels with the && operator:

agent(label 'builtin && jenkins-uk-win7')

as described here but it complains that there isn't an agent called 'builtin && jenkins-uk-win7'.

I've studied this post where people appear to be having similar problems to me regarding use of &&.

Surely this is a pretty elementary thing to do? Am I overlooking something painfully obvious?

1 Answer 1

1

Yes, the declarative syntax for what you are trying to do is verbose. And the pipeline-stage-view plugin doesn't help there. Give the pipeline-graph-view plugin a try, and if you still find it cumbersome your only other option is to use a scripted pipeline:

def agents = ['builtin', 'jenkins-uk-win7']
def stages = agents.collectEntries { agent -> [
    agent,
    {
        node(agent) {
            stage("$agent Checkout") {
                echo agent
                // whatever else you want to do
            }
            // other stages
        }
    }
]}

parallel(stages)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.