I'm trying to run automated tests in parallel on several devices using 
Jenkins. There is the matrix plugin for the parallel execution. I have 
several devices connected to the same agent and they have different 
parameters. Let's say

   - device1:
      - port: /dev/ttyUSB1
   - device2:
      - port: /dev/ttyUSB2
   
Then in the pipeline I need to know this parameter "port". So I do next:

pipeline {

  ...

  stages {

    stage('Checkout') {...}

    stage('Build') {...}

    stage('Parallel') {

      matrix {

        axes {

          name 'device_name'

          values 'device1', 'device2' 

        }

      }

     stages {

      stage('Flashing and testing') {

        steps {

          lock(resource: "${device_name}", variable: "${device}", quantity: 
1)

          echo "Device is ${device}"

           ...

          }

        }

      }

    }

  }

}

With that device is defined correctly, but how can I access it's port 
parameter? The documentation 
<https://plugins.jenkins.io/lockable-resources/> does not describe the case 
when there are several locks at the time. Though I can access the port with 
device0_port seems like it is the global variable and it is the same for 
all the parallel threads. I tried to call something like ${${device}0_port} but 
could not realize what should it be.

As a workaround I tried to move the parameters into the pipeline like

if ("${device}" == 'device1') {

  port = "/dev/ttyUSB1"

}

if ("${device}" == 'device2') {

  port = "/dev/ttyUSB2"

}

It does exactly what I need, but I suspect it is not the way it is supposed 
to be. 

So, my questions:


   1. Can lockable resources plugin work with matrix? Are there 
   alternatives?
   2. Should I report the bug about the variable scope?
   3. Is there a way to evaluate a variable name from the other variable?
   4. Other suggestions on making this code prettier?

Thank you in advance,
Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/jenkinsci-users/89b26acb-a4b0-42fa-a027-bf6d839ccd4fn%40googlegroups.com.

Reply via email to