Jenkins-矩阵作业-不同从属上的变量相互覆盖?
我想我不明白矩阵是如何工作的。当我在某个阶段中根据运行的节点设置某个变量时,在该阶段的其余部分,有时该变量被设置为它应该设置的,有时它从其他节点(轴)获取值。在下面的示例中,在ub18-1上运行的类似作业有时具有VARIABLE1='Linux node',有时是VARIABLE1='Windows node'。或者gitmethod有时它是从LinuxGitInfo创建的,有时是从WindowsGitInfo创建的 资料来源一基于 脚本和真实脚本几乎完全相同Jenkins-矩阵作业-不同从属上的变量相互覆盖?,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我想我不明白矩阵是如何工作的。当我在某个阶段中根据运行的节点设置某个变量时,在该阶段的其余部分,有时该变量被设置为它应该设置的,有时它从其他节点(轴)获取值。在下面的示例中,在ub18-1上运行的类似作业有时具有VARIABLE1='Linux node',有时是VARIABLE1='Windows node'。或者gitmethod有时它是从LinuxGitInfo创建的,有时是从WindowsGitInfo创建的 资料来源一基于 脚本和真实脚本几乎完全相同 @Library('firstl
@Library('firstlibrary') _
import mylib.shared.*
pipeline {
parameters {
booleanParam name: 'AUTO', defaultValue: true, description: 'Auto mode sets some parameters for every slave separately'
choice(name: 'SLAVE_NAME', choices:['all', 'ub18-1','win10'],description:'Run on specific platform')
string(name: 'BRANCH',defaultValue: 'master', description: 'Preferably common label for entire group')
booleanParam name: 'SONAR', defaultValue: false, description: 'Scan and gateway'
booleanParam name: 'DEPLOY', defaultValue: false, description: 'Deploy to Artifactory'
}
agent none
stages{
stage('BuildAndTest'){
matrix{
agent {
label "$NODE"
}
when{ anyOf{
expression { params.SLAVE_NAME == 'all'}
expression { params.SLAVE_NAME == env.NODE}
}}
axes{
axis{
name 'NODE'
values 'ub18-1', 'win10'
}
}
stages{
stage('auto mode'){
when{
expression { return params.AUTO }
}
steps{
echo "Setting parameters for each slave"
script{
nodeLabelsList = env.NODE_LABELS.split()
if (nodeLabelsList.contains('ub18-1')){
println("Setting params for ub18-1");
VARIABLE1 = 'Linux node'
}
if (nodeLabelsList.contains('win10')){
println("Setting params for Win10");
VARIABLE1 = 'Windows node'
}
if (isUnix()){
gitmethod = new LinuxGitInfo(this,env)
} else {
gitmethod = new WindowsGitInfo(this, env)
}
}
}
}
stage('GIT') {
steps {
checkout scm
}
}
stage('Info'){
steps{
script{
sh 'printenv'
echo "branch: " + env.BRANCH_NAME
echo "SLAVE_NAME: " + env.NODE_NAME
echo VARIABLE1
gitinfo = new GitInfo(gitmethod)
gitinfo.init()
echo gitinfo.author
echo gitinfo.id
echo gitinfo.msg
echo gitinfo.buildinfo
}
}
}
stage('install'){
steps{
sh 'make install'
}
}
stage('test'){
steps{
sh 'make test'
}
}
}
}
}
}
}
好的,我通过定义变量映射,将节点/从属名称作为键来解决这个问题。一些朋友甚至建议在存储库中的yml/json文件中定义变量并解析它们。也许我会的,但到目前为止效果不错 例如: 在管道之前
def DEPLOYmap = [
'ub18-1': false,
'win10': true
]
分阶段
when {
equals expected: true, actual: DEPLOYmap[NODE]
}
nodeLabelsList=env.NODE_LABELS.split()中的env.NODE_标签是什么?为什么不使用NODE来决定将哪个值分配给VARIABLE1呢?愚蠢的Jenkins。。。