首页 > 解决方案 > 通过 groovy 脚本创建 pipelineJob 环境变量的问题

问题描述

https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-environmentVariables-groovy真的有效吗?

可能更多是插件问题。

设置环境变量的常规脚本似乎适用于自由式工作。但我不能让他们从事管道工作。它们不会导致任何错误,但也不会设置环境变量。

其他人玩过它吗?

pipelineJob('example') {
  environmentVariables {
    env('ONE', '1')
    env('TWO', '2')
    groovy('''
    def a = 1
    return [THREE: 3 * a]
    ''')
  }
  
  definition {
    cps {
      script('''
      pipeline {
        agent any
        
        stages {
          stage('Env') {
            steps {
              sh 'env'
            }
          }
        }
      }
      
      ''')
    }
  }
}

谢谢

标签: jenkins-pipelinejenkins-pluginsjenkins-job-dsl

解决方案


推荐阅读