首页 > 解决方案 > 如何访问标签中轴的值?

问题描述

...
        matrix {
            axes {
              axis {
                name 'FOO'
                values 'foo1' 'foo2'   // 
              }
...            stages {
                stage ('doIt') {
                    agent{
                      label '???'
                    }
                
...

我想建立一个指令,如果也找到 FOO 的值之一label,它将接受win或。mac如何将轴的值与其他字符串组合以形成有意义的标签?

标签: jenkins-pipeline

解决方案


您可以通过名称访问轴变量 - FOO。您唯一需要记住的是在双引号字符串中使用它,以便可以正确插入该值。

pipeline {
    agent none
    stages {
        stage('Matrix example') {
            matrix {
                agent any
                axes {
                    axis {
                        name 'FOO'
                        values 'bar1', 'bar2', 'bar3'
                    }
                }
                stages {
                    stage('Test') {
                        agent {
                            label "${FOO}"
                        }
                        steps {
                            // ...
                        }
                    }
                }
            }
        }
    }
}


推荐阅读